diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /models | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'models')
| -rw-r--r-- | models/DecodeHighlightingModel.cpp | 386 | ||||
| -rw-r--r-- | models/DecodeHighlightingModel.hpp | 32 | ||||
| -rw-r--r-- | models/FrequencyList.cpp | 147 | ||||
| -rw-r--r-- | models/FrequencyList.hpp | 16 | ||||
| -rw-r--r-- | models/FrequencySuggestions.cpp | 164 | ||||
| -rw-r--r-- | models/FrequencySuggestions.hpp | 44 | ||||
| -rw-r--r-- | models/IARURegions.cpp | 10 | ||||
| -rw-r--r-- | models/IARURegions.hpp | 1 |
8 files changed, 725 insertions, 75 deletions
diff --git a/models/DecodeHighlightingModel.cpp b/models/DecodeHighlightingModel.cpp index ab504268..448f1d09 100644 --- a/models/DecodeHighlightingModel.cpp +++ b/models/DecodeHighlightingModel.cpp @@ -1,5 +1,7 @@ #include "DecodeHighlightingModel.hpp" +#include <algorithm> + #include <QString> #include <QVariant> #include <QList> @@ -7,6 +9,7 @@ #include <QColor> #include <QFont> #include <QMap> +#include <QHash> #include <QVector> #include <QTextStream> #include <QDataStream> @@ -17,6 +20,75 @@ #include "moc_DecodeHighlightingModel.cpp" +namespace +{ + using Highlight = DecodeHighlightingModel::Highlight; + using HighlightItems = DecodeHighlightingModel::HighlightItems; + using ColorPreset = DecodeHighlightingModel::ColorPreset; + + struct HighlightBehavior final + { + Highlight type_; + bool enabled_; + }; + using HighlightBehaviorItems = QList<HighlightBehavior>; + + HighlightItems make_highlight_items (HighlightBehaviorItems const& behavior, ColorPreset const& colors) + { + HighlightItems items; + for (auto const& behavior_item : behavior) + { + auto const color = std::find_if (colors.cbegin (), colors.cend (), [&behavior_item] (auto const& candidate) { + return candidate.type_ == behavior_item.type_; + }); + Q_ASSERT (color != colors.cend ()); + if (color != colors.cend ()) + { + items.append ({behavior_item.type_, behavior_item.enabled_, color->foreground_, color->background_}); + } + } + return items; + } + + HighlightBehaviorItems const default_behavior = { + {Highlight::MyCall, true} + , {Highlight::Continent, true} + , {Highlight::ContinentBand, true} + , {Highlight::CQZone, true} + , {Highlight::CQZoneBand, true} + , {Highlight::ITUZone, false} + , {Highlight::ITUZoneBand, false} + , {Highlight::DXCC, true} + , {Highlight::DXCCBand, true} + , {Highlight::Grid, false} + , {Highlight::GridBand, false} + , {Highlight::Call, false} + , {Highlight::CallBand, false} + , {Highlight::LotW, false} + , {Highlight::CQ, true} + , {Highlight::Tx, true} + }; + + HighlightBehaviorItems const default2_behavior = { + {Highlight::LotW, true} + , {Highlight::MyCall, true} + , {Highlight::Continent, true} + , {Highlight::ContinentBand, true} + , {Highlight::DXCC, true} + , {Highlight::DXCCBand, true} + , {Highlight::CQZone, true} + , {Highlight::CQZoneBand, true} + , {Highlight::ITUZone, true} + , {Highlight::ITUZoneBand, true} + , {Highlight::Grid, true} + , {Highlight::GridBand, true} + , {Highlight::Call, true} + , {Highlight::CallBand, true} + , {Highlight::CQ, true} + , {Highlight::Tx, true} + }; +} + class DecodeHighlightingModel::impl final { public: @@ -27,48 +99,176 @@ public: HighlightItems static const defaults_; HighlightItems static const defaults2_; + ColorPreset static const default_colors_; + ColorPreset static const default2_colors_; + ColorPreset static const red_green_color_vision_colors_; + ColorPreset static const blue_yellow_color_vision_colors_; + ColorPreset static const high_contrast_colors_; + ColorPreset static const dark_shack_colors_; + ColorPreset static const solarized_colors_; + ColorPreset static const monochrome_colors_; HighlightItems data_; QFont font_; }; -QList<DecodeHighlightingModel::HighlightInfo> const DecodeHighlightingModel::impl::defaults_ = { - {Highlight::MyCall, true, {}, {{0xff, 0x66, 0x66}}} - , {Highlight::Continent, true, {}, {{0xff, 0x00, 0x63}}} - , {Highlight::ContinentBand, true, {}, {{0xff, 0x99, 0xc2}}} - , {Highlight::CQZone, true, {}, {{0xff, 0xbf, 0x00}}} - , {Highlight::CQZoneBand, true, {}, {{0xff, 0xe4, 0x99}}} - , {Highlight::ITUZone, false, {}, {{0xa6, 0xff, 0x00}}} - , {Highlight::ITUZoneBand, false, {}, {{0xdd, 0xff, 0x99}}} - , {Highlight::DXCC, true, {}, {{0xff, 0x00, 0xff}}} - , {Highlight::DXCCBand, true, {}, {{0xff, 0xaa, 0xff}}} - , {Highlight::Grid, false, {}, {{0xff, 0x80, 0x00}}} - , {Highlight::GridBand, false, {}, {{0xff, 0xcc, 0x99}}} - , {Highlight::Call, false, {}, {{0x00, 0xff, 0xff}}} - , {Highlight::CallBand, false, {}, {{0x99, 0xff, 0xff}}} - , {Highlight::LotW, false, {{0x99, 0x00, 0x00}}, {}} - , {Highlight::CQ, true, {}, {{0x66, 0xff, 0x66}}} - , {Highlight::Tx, true, {}, {Qt::yellow}} +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::default_colors_ = { + {Highlight::MyCall, {}, {{0xff, 0x66, 0x66}}} + , {Highlight::Continent, {}, {{0xff, 0x00, 0x63}}} + , {Highlight::ContinentBand, {}, {{0xff, 0x99, 0xc2}}} + , {Highlight::CQZone, {}, {{0xff, 0xbf, 0x00}}} + , {Highlight::CQZoneBand, {}, {{0xff, 0xe4, 0x99}}} + , {Highlight::ITUZone, {}, {{0xa6, 0xff, 0x00}}} + , {Highlight::ITUZoneBand, {}, {{0xdd, 0xff, 0x99}}} + , {Highlight::DXCC, {}, {{0xff, 0x00, 0xff}}} + , {Highlight::DXCCBand, {}, {{0xff, 0xaa, 0xff}}} + , {Highlight::Grid, {}, {{0xff, 0x80, 0x00}}} + , {Highlight::GridBand, {}, {{0xff, 0xcc, 0x99}}} + , {Highlight::Call, {}, {{0x00, 0xff, 0xff}}} + , {Highlight::CallBand, {}, {{0x99, 0xff, 0xff}}} + , {Highlight::LotW, {{0x99, 0x00, 0x00}}, {}} + , {Highlight::CQ, {}, {{0x66, 0xff, 0x66}}} + , {Highlight::Tx, {}, {Qt::yellow}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::default2_colors_ = { + {Highlight::LotW, {Qt::black}, {}} + , {Highlight::MyCall, {{0xaa, 0x00, 0x00}}, {{0x00, 0xff, 0xff}}} + , {Highlight::Continent, {{0xaa, 0x00, 0x00}}, {{0xff, 0x50, 0xff}}} + , {Highlight::ContinentBand, {{0xaa, 0x00, 0x00}}, {{0xff, 0x82, 0xff}}} + , {Highlight::DXCC, {{0xaa, 0x00, 0x00}}, {Qt::yellow}} + , {Highlight::DXCCBand, {{0xaa, 0x00, 0x00}}, {{0xff, 0xff, 0x9b}}} + , {Highlight::CQZone, {{0xaa, 0x00, 0x00}}, {{0xaa, 0xaa, 0x00}}} + , {Highlight::CQZoneBand, {{0xaa, 0x00, 0x00}}, {{0xaa, 0xaa, 0x7f}}} + , {Highlight::ITUZone, {{0xaa, 0x00, 0x00}}, {{0x37, 0xbd, 0xff}}} + , {Highlight::ITUZoneBand, {{0xaa, 0x00, 0x00}}, {{0x91, 0xde, 0xff}}} + , {Highlight::Grid, {{0xaa, 0x00, 0x00}}, {{0xff, 0xa8, 0x80}}} + , {Highlight::GridBand, {{0xaa, 0x00, 0x00}}, {{0xff, 0xcd, 0x9b}}} + , {Highlight::Call, {{0xaa, 0x00, 0x00}}, {{0x64, 0xff, 0x64}}} + , {Highlight::CallBand, {{0xaa, 0x00, 0x00}}, {{0xb4, 0xff, 0xb4}}} + , {Highlight::CQ, {{0xaa, 0x00, 0x00}}, {{0xc3, 0xc3, 0xc3}}} + , {Highlight::Tx, {Qt::black}, {{0xff, 0xa5, 0xc6}}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::red_green_color_vision_colors_ = { + {Highlight::MyCall, {Qt::black}, {{0xd5, 0x5e, 0x00}}} + , {Highlight::Continent, {Qt::white}, {{0x00, 0x72, 0xb2}}} + , {Highlight::ContinentBand, {Qt::black}, {{0xa8, 0xcc, 0xe3}}} + , {Highlight::CQZone, {Qt::black}, {{0xe6, 0x9f, 0x00}}} + , {Highlight::CQZoneBand, {Qt::black}, {{0xf5, 0xd9, 0x99}}} + , {Highlight::ITUZone, {Qt::black}, {{0x56, 0xb4, 0xe9}}} + , {Highlight::ITUZoneBand, {Qt::black}, {{0xbe, 0xe3, 0xf5}}} + , {Highlight::DXCC, {Qt::black}, {{0xcc, 0x79, 0xa7}}} + , {Highlight::DXCCBand, {Qt::black}, {{0xe8, 0xbf, 0xd6}}} + , {Highlight::Grid, {Qt::white}, {Qt::black}} + , {Highlight::GridBand, {Qt::black}, {{0xcc, 0xcc, 0xcc}}} + , {Highlight::Call, {Qt::black}, {{0x99, 0x99, 0x99}}} + , {Highlight::CallBand, {Qt::black}, {{0xdd, 0xdd, 0xdd}}} + , {Highlight::LotW, {{0x00, 0x55, 0x44}}, {Qt::white}} + , {Highlight::CQ, {Qt::black}, {{0x00, 0x9e, 0x73}}} + , {Highlight::Tx, {Qt::black}, {{0xf0, 0xe4, 0x42}}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::blue_yellow_color_vision_colors_ = { + {Highlight::MyCall, {Qt::white}, {{0xe4, 0x1a, 0x1c}}} + , {Highlight::Continent, {Qt::black}, {{0xf7, 0x81, 0xbf}}} + , {Highlight::ContinentBand, {Qt::black}, {{0xfc, 0xe0, 0xef}}} + , {Highlight::CQZone, {Qt::white}, {{0xa6, 0x56, 0x28}}} + , {Highlight::CQZoneBand, {Qt::black}, {{0xe3, 0xc6, 0xb3}}} + , {Highlight::ITUZone, {Qt::white}, {{0xb0, 0x30, 0x60}}} + , {Highlight::ITUZoneBand, {Qt::black}, {{0xe8, 0xb9, 0xc7}}} + , {Highlight::DXCC, {Qt::white}, {{0x98, 0x4e, 0xa3}}} + , {Highlight::DXCCBand, {Qt::black}, {{0xe0, 0xc6, 0xe6}}} + , {Highlight::Grid, {Qt::black}, {{0x99, 0x99, 0x99}}} + , {Highlight::GridBand, {Qt::black}, {{0xdd, 0xdd, 0xdd}}} + , {Highlight::Call, {Qt::black}, {{0xfd, 0xbf, 0x6f}}} + , {Highlight::CallBand, {Qt::black}, {{0xfd, 0xe9, 0xd0}}} + , {Highlight::LotW, {{0x6e, 0x14, 0x23}}, {Qt::white}} + , {Highlight::CQ, {Qt::black}, {{0x4d, 0xaf, 0x4a}}} + , {Highlight::Tx, {Qt::black}, {{0xff, 0x7f, 0x00}}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::high_contrast_colors_ = { + {Highlight::MyCall, {Qt::black}, {{0xff, 0x00, 0x00}}} + , {Highlight::Continent, {Qt::black}, {{0xff, 0x80, 0x00}}} + , {Highlight::ContinentBand, {Qt::white}, {{0x99, 0x50, 0x00}}} + , {Highlight::CQZone, {Qt::white}, {{0x00, 0x40, 0xff}}} + , {Highlight::CQZoneBand, {Qt::white}, {{0x00, 0x29, 0x66}}} + , {Highlight::ITUZone, {Qt::white}, {{0x00, 0x80, 0x80}}} + , {Highlight::ITUZoneBand, {Qt::white}, {{0x00, 0x4d, 0x4d}}} + , {Highlight::DXCC, {Qt::white}, {{0xcc, 0x00, 0xcc}}} + , {Highlight::DXCCBand, {Qt::white}, {{0x7a, 0x00, 0x7a}}} + , {Highlight::Grid, {Qt::white}, {{0x66, 0x66, 0x66}}} + , {Highlight::GridBand, {Qt::white}, {{0x33, 0x33, 0x33}}} + , {Highlight::Call, {Qt::white}, {{0xd6, 0x00, 0x6d}}} + , {Highlight::CallBand, {Qt::white}, {{0x80, 0x00, 0x41}}} + , {Highlight::LotW, {{0x00, 0x1a, 0x66}}, {Qt::white}} + , {Highlight::CQ, {Qt::black}, {{0x00, 0xa0, 0x00}}} + , {Highlight::Tx, {Qt::black}, {{0xff, 0xff, 0x00}}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::dark_shack_colors_ = { + {Highlight::MyCall, {{0xff, 0xf6, 0xf2}}, {{0x8a, 0x24, 0x32}}} + , {Highlight::Continent, {{0xf2, 0xee, 0xe3}}, {{0x7c, 0x5a, 0x10}}} + , {Highlight::ContinentBand, {{0xd9, 0xd4, 0xc8}}, {{0x4a, 0x3d, 0x1f}}} + , {Highlight::CQZone, {{0xf2, 0xee, 0xe3}}, {{0x1d, 0x60, 0x78}}} + , {Highlight::CQZoneBand, {{0xd5, 0xdd, 0xe0}}, {{0x25, 0x3f, 0x49}}} + , {Highlight::ITUZone, {{0xf2, 0xee, 0xe3}}, {{0x1f, 0x66, 0x5e}}} + , {Highlight::ITUZoneBand, {{0xd3, 0xdd, 0xda}}, {{0x29, 0x43, 0x3f}}} + , {Highlight::DXCC, {{0xf8, 0xee, 0xf9}}, {{0x6d, 0x34, 0x7d}}} + , {Highlight::DXCCBand, {{0xdd, 0xd1, 0xdf}}, {{0x49, 0x30, 0x4f}}} + , {Highlight::Grid, {{0xf7, 0xee, 0xe5}}, {{0x7a, 0x46, 0x1c}}} + , {Highlight::GridBand, {{0xdb, 0xd2, 0xc9}}, {{0x4a, 0x38, 0x28}}} + , {Highlight::Call, {{0xe7, 0xf0, 0xe3}}, {{0x3e, 0x5d, 0x37}}} + , {Highlight::CallBand, {{0xd1, 0xda, 0xcd}}, {{0x30, 0x3f, 0x2f}}} + , {Highlight::LotW, {{0xb9, 0xd6, 0xdc}}, {{0x17, 0x31, 0x3a}}} + , {Highlight::CQ, {{0xc1, 0xdf, 0xc7}}, {{0x17, 0x33, 0x23}}} + , {Highlight::Tx, {{0xff, 0xf0, 0xaa}}, {{0x5f, 0x4a, 0x10}}} +}; + +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::solarized_colors_ = { + {Highlight::MyCall, {{0xfd, 0xf6, 0xe3}}, {{0xc4, 0x2d, 0x2a}}} + , {Highlight::Continent, {{0x00, 0x2b, 0x36}}, {{0xb5, 0x89, 0x00}}} + , {Highlight::ContinentBand, {{0xee, 0xe8, 0xd5}}, {{0x5c, 0x49, 0x0f}}} + , {Highlight::CQZone, {{0x00, 0x2b, 0x36}}, {{0x2a, 0xa1, 0x98}}} + , {Highlight::CQZoneBand, {{0xee, 0xe8, 0xd5}}, {{0x15, 0x56, 0x50}}} + , {Highlight::ITUZone, {{0x00, 0x2b, 0x36}}, {{0x85, 0x99, 0x00}}} + , {Highlight::ITUZoneBand, {{0xee, 0xe8, 0xd5}}, {{0x46, 0x52, 0x0a}}} + , {Highlight::DXCC, {{0xfd, 0xf6, 0xe3}}, {{0xbd, 0x2f, 0x75}}} + , {Highlight::DXCCBand, {{0xee, 0xe8, 0xd5}}, {{0x6f, 0x24, 0x49}}} + , {Highlight::Grid, {{0x00, 0x2b, 0x36}}, {{0x3a, 0x9e, 0xe0}}} + , {Highlight::GridBand, {{0xee, 0xe8, 0xd5}}, {{0x16, 0x57, 0x7c}}} + , {Highlight::Call, {{0xfd, 0xf6, 0xe3}}, {{0x5d, 0x62, 0xad}}} + , {Highlight::CallBand, {{0xee, 0xe8, 0xd5}}, {{0x3f, 0x42, 0x79}}} + , {Highlight::LotW, {{0x2a, 0xa1, 0x98}}, {{0x00, 0x2b, 0x36}}} + , {Highlight::CQ, {{0x93, 0xa1, 0xa1}}, {{0x07, 0x36, 0x42}}} + , {Highlight::Tx, {{0xfd, 0xf6, 0xe3}}, {{0xb8, 0x43, 0x14}}} }; -QList<DecodeHighlightingModel::HighlightInfo> const DecodeHighlightingModel::impl::defaults2_ = { - {Highlight::LotW, true, {Qt::black}, {}} - , {Highlight::MyCall, true, {{0xaa, 0x00, 0x00}}, {{0x00, 0xff, 0xff}}} - , {Highlight::Continent, true, {{0xaa, 0x00, 0x00}}, {{0xff, 0x50, 0xff}}} - , {Highlight::ContinentBand, true, {{0xaa, 0x00, 0x00}}, {{0xff, 0x82, 0xff}}} - , {Highlight::DXCC, true, {{0xaa, 0x00, 0x00}}, {Qt::yellow}} - , {Highlight::DXCCBand, true, {{0xaa, 0x00, 0x00}}, {{0xff, 0xff, 0x9b}}} - , {Highlight::CQZone, true, {{0xaa, 0x00, 0x00}}, {{0xaa, 0xaa, 0x00}}} - , {Highlight::CQZoneBand, true, {{0xaa, 0x00, 0x00}}, {{0xaa, 0xaa, 0x7f}}} - , {Highlight::ITUZone, true, {{0xaa, 0x00, 0x00}}, {{0x37, 0xbd, 0xff}}} - , {Highlight::ITUZoneBand, true, {{0xaa, 0x00, 0x00}}, {{0x91, 0xde, 0xff}}} - , {Highlight::Grid, true, {{0xaa, 0x00, 0x00}}, {{0xff, 0xa8, 0x80}}} - , {Highlight::GridBand, true, {{0xaa, 0x00, 0x00}}, {{0xff, 0xcd, 0x9b}}} - , {Highlight::Call, true, {{0xaa, 0x00, 0x00}}, {{0x64, 0xff, 0x64}}} - , {Highlight::CallBand, true, {{0xaa, 0x00, 0x00}}, {{0xb4, 0xff, 0xb4}}} - , {Highlight::CQ, true, {{0xaa, 0x00, 0x00}}, {{0xc3, 0xc3, 0xc3}}} - , {Highlight::Tx, true, {Qt::black}, {{0xff, 0xa5, 0xc6}}} +DecodeHighlightingModel::ColorPreset const DecodeHighlightingModel::impl::monochrome_colors_ = { + {Highlight::MyCall, {Qt::white}, {Qt::black}} + , {Highlight::Continent, {Qt::black}, {{0xf5, 0xf5, 0xf5}}} + , {Highlight::ContinentBand, {Qt::black}, {{0xc8, 0xc8, 0xc8}}} + , {Highlight::CQZone, {Qt::white}, {{0x1f, 0x1f, 0x1f}}} + , {Highlight::CQZoneBand, {Qt::white}, {{0x55, 0x55, 0x55}}} + , {Highlight::ITUZone, {Qt::black}, {{0xde, 0xde, 0xde}}} + , {Highlight::ITUZoneBand, {Qt::black}, {{0xa8, 0xa8, 0xa8}}} + , {Highlight::DXCC, {Qt::white}, {{0x17, 0x17, 0x17}}} + , {Highlight::DXCCBand, {Qt::white}, {{0x45, 0x45, 0x45}}} + , {Highlight::Grid, {Qt::black}, {{0xd0, 0xd0, 0xd0}}} + , {Highlight::GridBand, {Qt::white}, {{0x58, 0x58, 0x58}}} + , {Highlight::Call, {Qt::black}, {{0xb8, 0xb8, 0xb8}}} + , {Highlight::CallBand, {Qt::white}, {{0x66, 0x66, 0x66}}} + , {Highlight::LotW, {{0xd0, 0xd0, 0xd0}}, {{0x33, 0x33, 0x33}}} + , {Highlight::CQ, {{0xc0, 0xc0, 0xc0}}, {{0x3f, 0x3f, 0x3f}}} + , {Highlight::Tx, {{0x11, 0x11, 0x11}}, {{0xef, 0xef, 0xef}}} }; +DecodeHighlightingModel::HighlightItems const DecodeHighlightingModel::impl::defaults_ = + make_highlight_items (default_behavior, default_colors_); + +DecodeHighlightingModel::HighlightItems const DecodeHighlightingModel::impl::defaults2_ = + make_highlight_items (default2_behavior, default2_colors_); + bool operator == (DecodeHighlightingModel::HighlightInfo const& lhs, DecodeHighlightingModel::HighlightInfo const& rhs) { return lhs.type_ == rhs.type_ @@ -159,6 +359,72 @@ auto DecodeHighlightingModel::default_items2 () -> HighlightItems const& return impl::defaults2_; } +auto DecodeHighlightingModel::default_color_preset () -> ColorPreset const& +{ + return impl::default_colors_; +} + +auto DecodeHighlightingModel::default2_color_preset () -> ColorPreset const& +{ + return impl::default2_colors_; +} + +auto DecodeHighlightingModel::red_green_color_vision_preset () -> ColorPreset const& +{ + return impl::red_green_color_vision_colors_; +} + +auto DecodeHighlightingModel::blue_yellow_color_vision_preset () -> ColorPreset const& +{ + return impl::blue_yellow_color_vision_colors_; +} + +auto DecodeHighlightingModel::high_contrast_color_preset () -> ColorPreset const& +{ + return impl::high_contrast_colors_; +} + +auto DecodeHighlightingModel::dark_shack_color_preset () -> ColorPreset const& +{ + return impl::dark_shack_colors_; +} + +auto DecodeHighlightingModel::solarized_color_preset () -> ColorPreset const& +{ + return impl::solarized_colors_; +} + +auto DecodeHighlightingModel::monochrome_color_preset () -> ColorPreset const& +{ + return impl::monochrome_colors_; +} + +auto DecodeHighlightingModel::resolve_colors (HighlightItems const& items, HighlightTypes const& types, + QColor background, QColor foreground) -> ResolvedHighlight +{ + ResolvedHighlight result {Highlight::CQ, background, foreground}; + QListIterator<HighlightInfo> it {items}; + // Earlier rows have higher priority, so apply matching rules from last to first. + it.toBack (); + while (it.hasPrevious ()) + { + auto const& item = it.previous (); + if (std::find (types.cbegin (), types.cend (), item.type_) != types.cend () && item.enabled_) + { + if (item.background_.style () != Qt::NoBrush) + { + result.background_ = item.background_.color (); + } + if (item.foreground_.style () != Qt::NoBrush) + { + result.foreground_ = item.foreground_.color (); + } + result.type_ = item.type_; + } + } + return result; +} + auto DecodeHighlightingModel::items () const -> HighlightItems const& { return m_->data_; @@ -183,6 +449,56 @@ void DecodeHighlightingModel::items (HighlightItems const& items) } } +bool DecodeHighlightingModel::apply_color_preset (ColorPreset const& preset) +{ + if (m_->data_.isEmpty ()) + { + return false; + } + + // Index the preset by rule type; a duplicated type makes the preset ambiguous. + QHash<int, HighlightColors const *> colors; + colors.reserve (preset.size ()); + for (auto const& entry : preset) + { + auto const key = static_cast<int> (entry.type_); + if (colors.contains (key)) + { + return false; + } + colors.insert (key, &entry); + } + + // Validate that every rule has a color before touching the model. + for (auto const& item : m_->data_) + { + if (!colors.contains (static_cast<int> (item.type_))) + { + return false; + } + } + + bool changed {false}; + for (auto& item : m_->data_) + { + auto const entry = colors.value (static_cast<int> (item.type_)); + if (item.foreground_ != entry->foreground_ || item.background_ != entry->background_) + { + item.foreground_ = entry->foreground_; + item.background_ = entry->background_; + changed = true; + } + } + + if (changed) + { + QVector<int> roles; + roles << Qt::DisplayRole << Qt::ForegroundRole << Qt::BackgroundRole; + Q_EMIT dataChanged (index (0, 0), index (rowCount () - 1, 0), roles); + } + return true; +} + void DecodeHighlightingModel::set_font (QFont const& font) { m_->font_ = font; @@ -330,6 +646,7 @@ bool DecodeHighlightingModel::setData (QModelIndex const& index, QVariant const& if (item.foreground_ != value.value<QBrush> ()) { item.foreground_ = value.value<QBrush> (); + roles << Qt::DisplayRole; Q_EMIT dataChanged (index, index, roles); } ok = true; @@ -338,6 +655,7 @@ bool DecodeHighlightingModel::setData (QModelIndex const& index, QVariant const& if (item.background_ != value.value<QBrush> ()) { item.background_ = value.value<QBrush> (); + roles << Qt::DisplayRole; Q_EMIT dataChanged (index, index, roles); } ok = true; diff --git a/models/DecodeHighlightingModel.hpp b/models/DecodeHighlightingModel.hpp index 839b3ba4..eedcaa1b 100644 --- a/models/DecodeHighlightingModel.hpp +++ b/models/DecodeHighlightingModel.hpp @@ -3,8 +3,11 @@ #include <QAbstractListModel> #include <QBrush> +#include <QColor> #include <QList> +#include <vector> + #include "qt_helpers.hpp" #include "pimpl_h.hpp" @@ -34,14 +37,41 @@ public: }; using HighlightItems = QList<HighlightInfo>; + struct ResolvedHighlight final + { + Highlight type_; + QColor background_; + QColor foreground_; + }; + using HighlightTypes = std::vector<Highlight>; + + struct HighlightColors final + { + Highlight type_; + QBrush foreground_; + QBrush background_; + }; + using ColorPreset = QList<HighlightColors>; + explicit DecodeHighlightingModel (QObject * parent = 0); ~DecodeHighlightingModel(); - // access to raw items nd default items + // access to raw items and default items static HighlightItems const& default_items (); static HighlightItems const& default_items2 (); + static ColorPreset const& default_color_preset (); + static ColorPreset const& default2_color_preset (); + static ColorPreset const& red_green_color_vision_preset (); + static ColorPreset const& blue_yellow_color_vision_preset (); + static ColorPreset const& high_contrast_color_preset (); + static ColorPreset const& dark_shack_color_preset (); + static ColorPreset const& solarized_color_preset (); + static ColorPreset const& monochrome_color_preset (); + static ResolvedHighlight resolve_colors (HighlightItems const&, HighlightTypes const&, + QColor background, QColor foreground); HighlightItems const& items () const; void items (HighlightItems const&); + bool apply_color_preset (ColorPreset const&); void set_font (QFont const&); diff --git a/models/FrequencyList.cpp b/models/FrequencyList.cpp index cc6ed129..04d896e1 100644 --- a/models/FrequencyList.cpp +++ b/models/FrequencyList.cpp @@ -69,9 +69,9 @@ namespace {1836800, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {1838000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // squeezed allocations {1839000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {1839000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // shares JT9's dial freq (JT9 now low-traffic) {1839000, Modes::FST4, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {1840000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, - {1838000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency // Band plans (all USB dial unless stated otherwise) // @@ -103,12 +103,12 @@ namespace {3567000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // DXpedition {3570000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // JA compatible {3572000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {3572000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // shares JT9's dial freq (JT9 now low-traffic) {3573000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // above as below JT65 is out of DM allocation {3568600, Modes::WSPR, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // needs guard marker and lock out {3568600, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // needs guard marker and lock out {3575000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional {3568000, Modes::FT4, IARURegions::R3, "","", QDateTime(), QDateTime(), false}, // provisional - {3575000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // stays under R3's narrow DM segment (documented above as ending at 3575-3580) even with the 1500 Hz audio offset added {5357000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // provisional {5357000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // provisional @@ -152,10 +152,10 @@ namespace {7074000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {7076000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {7078000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {7078000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // shares JT9's dial freq (JT9 now low-traffic) {7047500, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional - moved // up 500Hz to clear // W1AW code practice QRG - {7090000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY freq + 10 kHz // Band plans (all USB dial unless stated otherwise) // @@ -190,7 +190,7 @@ namespace {10138700, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {10140000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {10140000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional - {10140000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency; band's upper edge (10150) leaves no room for the usual +10 kHz nudge + {10140000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency; band's upper edge (10150) leaves no room for a +10 kHz nudge // Band plans (all USB dial unless stated otherwise) // @@ -238,7 +238,6 @@ namespace {14080000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional {14090000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY freq + 10 kHz - // Band plans (all USB dial unless stated otherwise) // // R1: 18095 - 18109 DM NB(<500Hz) with 18105 - 18109 ACDS @@ -270,10 +269,10 @@ namespace {18100000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {18102000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {18104000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {18104000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // shares JT9's dial freq -- off FT8's 18100 and clear of the 18110 NCDXF beacon {18104000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional {18104600, Modes::WSPR, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {18104600, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, - {18100000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency; +10 kHz would put the 1500 Hz-offset signal past the US data segment's 18110 kHz edge (and onto the NCDXF beacon frequency) {21074000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {21091000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // DXpedition @@ -289,19 +288,20 @@ namespace {24917000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {24919000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {24919000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // provisional + {24920000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency; US narrow data segment (24920-24925) leaves no room for a +10 kHz nudge {24924600, Modes::WSPR, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {24924600, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, - {24920000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY frequency; the US narrow data segment (24920-24925) leaves no room for the usual +10 kHz nudge once the 1500 Hz audio offset is added {28074000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {28091000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, // DXpedition {28076000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {28078000, Modes::JT9, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {28090000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY freq + 10 kHz {28124600, Modes::WSPR, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {28124600, Modes::FST4W, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {28180000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, - {28090000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, // conventional RTTY freq + 10 kHz + {50160000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {50200000, Modes::Echo, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {50211000, Modes::Q65, IARURegions::ALL, "EME","", QDateTime(), QDateTime(), false}, {50275000, Modes::Q65, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, @@ -330,6 +330,7 @@ namespace {144116000, Modes::Q65, IARURegions::ALL, "EME","", QDateTime(), QDateTime(), false}, {144120000, Modes::JT65, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, {144120000, Modes::Echo, IARURegions::ALL, "","", QDateTime(), QDateTime(), false}, + {144160000, Modes::JTTY, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {144170000, Modes::FT4, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {144174000, Modes::FT8, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, {144180000, Modes::Q65, IARURegions::ALL, "","", QDateTime(), QDateTime(), true}, @@ -426,7 +427,7 @@ QString FrequencyList_v2_101::Item::toString () const } QJsonObject FrequencyList_v2_101::Item::toJson() const { - return {{"frequency", Radio::frequency_MHz_string (frequency_) }, + return {{"frequency", Radio::frequency_MHz_string (frequency_, 6, QLocale::c ()) }, {"mode", Modes::name (mode_) }, {"region", IARURegions::name (region_)}, {"description", description_}, @@ -524,6 +525,11 @@ auto FrequencyList_v2_101::frequency_list () const -> FrequencyItems const& return m_->frequency_list_; } +auto FrequencyList_v2_101::default_items () -> FrequencyItems const& +{ + return default_frequency_list; +} + auto FrequencyList_v2_101::frequency_list (QModelIndexList const& model_index_list) const -> FrequencyItems { FrequencyItems list; @@ -1363,9 +1369,55 @@ auto FrequencyList_v2_101::all_bands (Region region, Mode mode) const -> BandSet return result; } -FrequencyList_v2_101::FrequencyItems FrequencyList_v2_101::from_json_file(QFile *input_file) +namespace +{ + Radio::Frequency json_frequency (QString const& value, bool * ok) + { + auto const text = value.trimmed (); + bool c_locale_ok; + auto const c_locale_frequency = Radio::frequency (text, 6, &c_locale_ok, QLocale::c ()); + if (c_locale_ok && Radio::frequency_MHz_string (c_locale_frequency, 6, QLocale::c ()) == text) + { + *ok = true; + return c_locale_frequency; + } + static auto const locales = QLocale::matchingLocales (QLocale::AnyLanguage, + QLocale::AnyScript, + QLocale::AnyCountry); + for (auto const& locale : locales) + { + auto normalized = text; + auto const group_separator = locale.groupSeparator (); + normalized.replace (QChar::Nbsp, group_separator); + normalized.replace (QChar {0x202f}, group_separator); + normalized.replace (QChar {'\''}, group_separator); + normalized.replace (QChar {0x2019}, group_separator); + bool parsed; + auto const frequency = Radio::frequency (normalized, 6, &parsed, locale); + if (parsed && Radio::frequency_MHz_string (frequency, 6, locale) == normalized) + { + *ok = true; + return frequency; + } + } + if (text.contains (',') || text.contains (QChar {'\''}) + || text.contains (QChar {0x2019}) || text.contains (QChar::Nbsp) + || text.contains (QChar {0x202f}) || text.contains (QChar {0x066b}) + || text.contains (QChar {0x066c})) + { + *ok = false; + return 0; + } + *ok = c_locale_ok; + return c_locale_frequency; + } +} + +FrequencyList_v2_101::FrequencyItems FrequencyList_v2_101::from_json_file(QFile *input_file, + ImportReport * report) { FrequencyList_v2_101::FrequencyItems list; + ImportReport result; QJsonDocument doc = QJsonDocument::fromJson(input_file->readAll()); if (doc.isNull()) { @@ -1381,47 +1433,64 @@ FrequencyList_v2_101::FrequencyItems FrequencyList_v2_101::from_json_file(QFile { throw ReadFileException{tr ("No Frequencies were found")}; } -#ifdef DUMP_ENTRY_COUNTS - int valid_entry_count = 0; - int skipped_entry_count = 0; -#endif for (auto const &item: arr) { - QString mode_s, region_s; + ++result.entries; QJsonObject obj = item.toObject(); FrequencyList_v2_101::Item freq; - region_s = obj["region"].toString(); - mode_s = obj["mode"].toString(); + auto const region_s = obj["region"].toString().trimmed(); + auto const mode_s = obj["mode"].toString().trimmed(); - freq.frequency_ = obj["frequency"].toString().toDouble() * 1e6; - freq.region_ = IARURegions::value(region_s); - freq.mode_ = Modes::value(mode_s); + bool frequency_ok; + freq.frequency_ = json_frequency (obj["frequency"].toString(), &frequency_ok); + if (!frequency_ok || !freq.frequency_) + { + ++result.invalid_frequency; + continue; + } + freq.region_ = IARURegions::fromCanonicalName (region_s); + if (freq.region_ == IARURegions::SENTINAL) + { + ++result.invalid_region; + continue; + } + freq.mode_ = Modes::ALL; + bool mode_ok = mode_s.isEmpty (); + for (int mode = Modes::ALL; !mode_ok && mode < Modes::MODES_END_SENTINAL_AND_COUNT; ++mode) + { + auto const candidate = static_cast<Modes::Mode> (mode); + if (mode_s.compare (Modes::name (candidate), Qt::CaseInsensitive) == 0) + { + freq.mode_ = candidate; + mode_ok = true; + } + } + if (!mode_ok) + { + ++result.unknown_modes[mode_s]; + continue; + } freq.description_ = obj["description"].toString(); freq.source_ = obj["source"].toString(); - freq.start_time_ = QDateTime::fromString(obj["start_time"].toString(), Qt::ISODate); - freq.end_time_ = QDateTime::fromString(obj["end_time"].toString(), Qt::ISODate); + auto const start_time = obj["start_time"].toString().trimmed(); + auto const end_time = obj["end_time"].toString().trimmed(); + freq.start_time_ = QDateTime::fromString(start_time, Qt::ISODate); + freq.end_time_ = QDateTime::fromString(end_time, Qt::ISODate); freq.preferred_ = obj["preferred"].toBool(); - if ((freq.mode_ != Modes::ALL || QString::compare("ALL", mode_s)) && - (freq.region_ != IARURegions::ALL || QString::compare("ALL", region_s, Qt::CaseInsensitive)) && - freq.isSane()) + if ((start_time.isEmpty () || freq.start_time_.isValid ()) + && (end_time.isEmpty () || freq.end_time_.isValid ()) + && freq.isSane()) { list.push_back(freq); -#ifdef DUMP_ENTRY_COUNTS - valid_entry_count++; -#endif - } else { -#ifdef DUMP_ENTRY_COUNTS - skipped_entry_count++; -#endif - } + ++result.imported; + } + else + { + ++result.invalid_item; + } } - -#ifdef DUMP_ENTRY_COUNTS - MessageBox::information_message(this, tr("Loaded Frequencies from %1").arg(file_name), - tr("Entries Valid/Skipped %1").arg(QString::number(valid_entry_count) + "/" + - QString::number(skipped_entry_count))); -#endif + if (report) *report = result; return list; } diff --git a/models/FrequencyList.hpp b/models/FrequencyList.hpp index 04b51a86..b6af4b6d 100644 --- a/models/FrequencyList.hpp +++ b/models/FrequencyList.hpp @@ -4,6 +4,7 @@ #include "pimpl_h.hpp" #include <QList> +#include <QMap> #include <QSortFilterProxyModel> #include <QDateTime> #include <QJsonObject> @@ -70,6 +71,18 @@ public: using FrequencyItems = QList<Item>; using BandSet = QSet<QString>; + struct ImportReport + { + int entries {0}; + int imported {0}; + int invalid_frequency {0}; + QMap<QString, int> unknown_modes; + int invalid_region {0}; + int invalid_item {0}; + + int skipped () const { return entries - imported; } + }; + enum Column {region_column, mode_column, frequency_column, frequency_mhz_column, description_column, start_time_column, end_time_column, source_column, preferred_column, SENTINAL}; // an iterator that meets the requirements of the C++ for range statement @@ -100,10 +113,11 @@ public: // Load and store underlying items FrequencyItems frequency_list (FrequencyItems); FrequencyItems const& frequency_list () const; + static FrequencyItems const& default_items (); FrequencyItems frequency_list (QModelIndexList const&) const; void frequency_list_merge (FrequencyItems const&); void to_json_file(QFile *, QString, QString, FrequencyItems const&); - static FrequencyItems from_json_file(QFile *); + static FrequencyItems from_json_file(QFile *, ImportReport * = nullptr); // Iterators for the sorted and filtered items // diff --git a/models/FrequencySuggestions.cpp b/models/FrequencySuggestions.cpp new file mode 100644 index 00000000..a2a210a9 --- /dev/null +++ b/models/FrequencySuggestions.cpp @@ -0,0 +1,164 @@ +#include "models/FrequencySuggestions.hpp" + +#include "models/Bands.hpp" + +namespace +{ + bool region_covers (IARURegions::Region existing, IARURegions::Region suggestion) + { + return existing == suggestion || existing == IARURegions::ALL; + } + + bool mode_covers (Modes::Mode existing, Modes::Mode suggestion) + { + return existing == suggestion + || (existing == Modes::ALL && suggestion != Modes::FreqCal); + } + + bool regions_overlap (IARURegions::Region lhs, IARURegions::Region rhs) + { + return region_covers (lhs, rhs) || region_covers (rhs, lhs); + } + + bool modes_overlap (Modes::Mode lhs, Modes::Mode rhs) + { + return mode_covers (lhs, rhs) || mode_covers (rhs, lhs); + } + + bool contains_catalog (FrequencySuggestions::Items const& catalog, + FrequencySuggestions::Items const& working) + { + for (auto const& item : catalog) + if (!FrequencySuggestions::is_present (item, working)) return false; + return true; + } +} + +QString FrequencySuggestions::key (Item const& item) +{ + return QString::number (item.region_) + ':' + + QString::number (item.mode_) + ':' + + QString::number (item.frequency_); +} + +bool FrequencySuggestions::is_present (Item const& suggestion, Items const& working) +{ + for (auto const& item : working) + { + if (item.frequency_ == suggestion.frequency_ + && region_covers (item.region_, suggestion.region_) + && mode_covers (item.mode_, suggestion.mode_)) + { + return true; + } + } + return false; +} + +auto FrequencySuggestions::prepare_additions (Items const& selected, + Items const& working, + Bands const& bands) -> Items +{ + Items additions; + Items combined = working; + for (auto suggestion : selected) + { + if (is_present (suggestion, combined)) continue; + + if (suggestion.preferred_) + { + auto const band = bands.find (suggestion.frequency_); + for (auto const& item : combined) + { + if (item.preferred_ && !band.isEmpty () + && bands.find (item.frequency_) == band + && regions_overlap (item.region_, suggestion.region_) + && modes_overlap (item.mode_, suggestion.mode_)) + { + suggestion.preferred_ = false; + break; + } + } + } + + additions.append (suggestion); + combined.append (suggestion); + } + return additions; +} + +FrequencySuggestions::NoticeState::NoticeState (QStringList seen_keys, bool has_seen_catalog) + : has_seen_catalog_ {has_seen_catalog} +{ + for (auto const& key : seen_keys) seen_keys_.insert (key); +} + +auto FrequencySuggestions::NoticeState::visibility (Items const& catalog, + Items const& working) const -> Visibility +{ + bool missing {false}; + for (auto const& item : catalog) + { + if (is_present (item, working)) continue; + missing = true; + if (has_seen_catalog_ && !seen_keys_.contains (key (item))) return Visibility::New; + } + return missing && !has_seen_catalog_ ? Visibility::Available : Visibility::Hidden; +} + +void FrequencySuggestions::NoticeState::selected_additions (Items const& additions) +{ + pending_additions_ += additions; +} + +void FrequencySuggestions::NoticeState::cancel () +{ + pending_additions_.clear (); +} + +bool FrequencySuggestions::NoticeState::commit (Items const& catalog, + Items const& committed_working) +{ + bool saved_addition {false}; + for (auto const& item : pending_additions_) + if (is_present (item, committed_working)) + { + saved_addition = true; + break; + } + auto const acknowledge_catalog = saved_addition || contains_catalog (catalog, committed_working); + pending_additions_.clear (); + if (!acknowledge_catalog) return false; + acknowledge (catalog); + return true; +} + +bool FrequencySuggestions::NoticeState::acknowledge_present_catalog ( + Items const& catalog, Items const& committed_working) +{ + if (!contains_catalog (catalog, committed_working)) return false; + QSet<QString> keys; + for (auto const& item : catalog) keys.insert (key (item)); + if (has_seen_catalog_ && seen_keys_ == keys) return false; + acknowledge (catalog); + return true; +} + +void FrequencySuggestions::NoticeState::dismiss (Items const& catalog) +{ + acknowledge (catalog); +} + +QStringList FrequencySuggestions::NoticeState::seen_keys () const +{ + auto keys = seen_keys_.values (); + keys.sort (); + return keys; +} + +void FrequencySuggestions::NoticeState::acknowledge (Items const& catalog) +{ + seen_keys_.clear (); + for (auto const& item : catalog) seen_keys_.insert (key (item)); + has_seen_catalog_ = true; +} diff --git a/models/FrequencySuggestions.hpp b/models/FrequencySuggestions.hpp new file mode 100644 index 00000000..74ed2eb6 --- /dev/null +++ b/models/FrequencySuggestions.hpp @@ -0,0 +1,44 @@ +#ifndef FREQUENCY_SUGGESTIONS_HPP__ +#define FREQUENCY_SUGGESTIONS_HPP__ + +#include "models/FrequencyList.hpp" + +#include <QSet> +#include <QStringList> + +class Bands; + +namespace FrequencySuggestions +{ + using Item = FrequencyList_v2_101::Item; + using Items = FrequencyList_v2_101::FrequencyItems; + + QString key (Item const&); + bool is_present (Item const&, Items const& working); + Items prepare_additions (Items const& selected, Items const& working, Bands const&); + + class NoticeState + { + public: + enum class Visibility { Hidden, Available, New }; + + NoticeState (QStringList seen_keys = {}, bool has_seen_catalog = false); + + Visibility visibility (Items const& catalog, Items const& working) const; + void selected_additions (Items const& additions); + void cancel (); + bool commit (Items const& catalog, Items const& committed_working); + bool acknowledge_present_catalog (Items const& catalog, Items const& committed_working); + void dismiss (Items const& catalog); + QStringList seen_keys () const; + + private: + void acknowledge (Items const& catalog); + + QSet<QString> seen_keys_; + bool has_seen_catalog_ {false}; + Items pending_additions_; + }; +} + +#endif diff --git a/models/IARURegions.cpp b/models/IARURegions.cpp index 3f8f1c3e..99bc5a13 100644 --- a/models/IARURegions.cpp +++ b/models/IARURegions.cpp @@ -44,6 +44,16 @@ IARURegions::Region IARURegions::value (QString const& s) return p != end ? static_cast<Region> (p - region_names) : ALL; } +IARURegions::Region IARURegions::fromCanonicalName (QString const& s) +{ + auto end = region_names + region_names_size; + auto p = std::find_if (region_names, end + , [&s] (char const * const name) { + return name == s; + }); + return p != end ? static_cast<Region> (p - region_names) : SENTINAL; +} + QVariant IARURegions::data (QModelIndex const& index, int role) const { QVariant item; diff --git a/models/IARURegions.hpp b/models/IARURegions.hpp index 498846d3..b809b686 100644 --- a/models/IARURegions.hpp +++ b/models/IARURegions.hpp @@ -51,6 +51,7 @@ public: // translate between enumeration and human readable strings static char const * name (Region); static Region value (QString const&); + static Region fromCanonicalName (QString const&); // Implement the QAbstractListModel interface int rowCount (QModelIndex const& parent = QModelIndex {}) const override |
