diff --git a/scwx-qt/source/scwx/qt/settings/audio_settings.cpp b/scwx-qt/source/scwx/qt/settings/audio_settings.cpp index 2145daba..0ee04b2b 100644 --- a/scwx-qt/source/scwx/qt/settings/audio_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/audio_settings.cpp @@ -57,7 +57,10 @@ public: config::CountyDatabase::GetCountyName(value) != value; }); - for (auto& phenomenon : types::GetAlertAudioPhenomena()) + auto& alertAudioPhenomena = types::GetAlertAudioPhenomena(); + alertEnabled_.reserve(alertAudioPhenomena.size() + 1); + + for (auto& phenomenon : alertAudioPhenomena) { std::string phenomenonCode = awips::GetPhenomenonCode(phenomenon); std::string name = fmt::format("{}_enabled", phenomenonCode); diff --git a/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp b/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp index 0b22f9e9..e1398da5 100644 --- a/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp @@ -50,6 +50,8 @@ class HotkeySettings::Impl public: explicit Impl() { + hotkey_.reserve(types::HotkeyIterator().count() + 1); + for (const auto& hotkey : types::HotkeyIterator()) { const std::string& name = types::GetHotkeyShortName(hotkey); diff --git a/scwx-qt/source/scwx/qt/settings/palette_settings.cpp b/scwx-qt/source/scwx/qt/settings/palette_settings.cpp index b79bf4db..9d9c93fa 100644 --- a/scwx-qt/source/scwx/qt/settings/palette_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/palette_settings.cpp @@ -78,6 +78,8 @@ class PaletteSettings::Impl public: explicit Impl() { + palette_.reserve(kPaletteKeys_.size()); + for (const auto& name : kPaletteKeys_) { const std::string& defaultValue = kDefaultPalettes_.at(name); @@ -92,6 +94,9 @@ public: variables_.push_back(&settingsVariable); }; + activeAlertColor_.reserve(kAlertColors_.size()); + inactiveAlertColor_.reserve(kAlertColors_.size()); + for (auto& alert : kAlertColors_) { std::string phenomenonCode = awips::GetPhenomenonCode(alert.first); diff --git a/scwx-qt/source/scwx/qt/settings/text_settings.cpp b/scwx-qt/source/scwx/qt/settings/text_settings.cpp index 49b97c59..942ad4f8 100644 --- a/scwx-qt/source/scwx/qt/settings/text_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/text_settings.cpp @@ -122,6 +122,8 @@ TextSettings& TextSettings::operator=(TextSettings&&) noexcept = default; void TextSettings::Impl::InitializeFontVariables() { + fontData_.reserve(types::FontCategoryIterator().count()); + for (auto fontCategory : types::FontCategoryIterator()) { auto result = fontData_.emplace(fontCategory, FontData {}); diff --git a/scwx-qt/source/scwx/qt/ui/settings/hotkey_settings_widget.cpp b/scwx-qt/source/scwx/qt/ui/settings/hotkey_settings_widget.cpp index a636b78a..05583c9a 100644 --- a/scwx-qt/source/scwx/qt/ui/settings/hotkey_settings_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings/hotkey_settings_widget.cpp @@ -46,6 +46,8 @@ public: int row = 0; + hotkeys_.reserve(types::HotkeyIterator().count()); + for (types::Hotkey hotkey : types::HotkeyIterator()) { const std::string& labelText = types::GetHotkeyLongName(hotkey); diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index e0996855..07753f04 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -658,6 +658,8 @@ void SettingsDialogImpl::SetupPalettesColorTablesTab() QGridLayout* colorTableLayout = reinterpret_cast(self_->ui->colorTableContents->layout()); + colorTables_.reserve(kColorTableTypes_.size()); + int colorTableRow = 0; for (auto& colorTableType : kColorTableTypes_) { @@ -764,8 +766,13 @@ void SettingsDialogImpl::SetupPalettesAlertsTab() alertsLayout->addWidget(activeLabel, 0, 1, 1, 4); alertsLayout->addWidget(inactiveLabel, 0, 5, 1, 4); + auto& alertPhenomena = settings::PaletteSettings::alert_phenomena(); + + activeAlertColors_.reserve(alertPhenomena.size()); + inactiveAlertColors_.reserve(alertPhenomena.size()); + int alertsRow = 1; - for (auto& phenomenon : settings::PaletteSettings::alert_phenomena()) + for (auto& phenomenon : alertPhenomena) { QFrame* activeFrame = new QFrame(self_); QFrame* inactiveFrame = new QFrame(self_); @@ -963,10 +970,13 @@ void SettingsDialogImpl::SetupAudioTab() alertAudioLongitude_.SetResetButton( self_->ui->resetAlertAudioLongitudeButton); - auto alertAudioLayout = + auto& alertAudioPhenomena = types::GetAlertAudioPhenomena(); + auto alertAudioLayout = static_cast(self_->ui->alertAudioGroupBox->layout()); - for (const auto& phenomenon : types::GetAlertAudioPhenomena()) + alertAudioEnabled_.reserve(alertAudioPhenomena.size()); + + for (const auto& phenomenon : alertAudioPhenomena) { QCheckBox* alertAudioCheckbox = new QCheckBox(self_); alertAudioCheckbox->setText( @@ -1062,6 +1072,12 @@ void SettingsDialogImpl::SetupTextTab() settings::TextSettings& textSettings = settings::TextSettings::Instance(); self_->ui->fontListView->setModel(fontCategoryModel_); + + const auto fontCategoryCount = types::FontCategoryIterator().count(); + fontFamilies_.reserve(fontCategoryCount); + fontStyles_.reserve(fontCategoryCount); + fontPointSizes_.reserve(fontCategoryCount); + for (const auto& fontCategory : types::FontCategoryIterator()) { // Add font category to list view diff --git a/wxdata/include/scwx/util/iterator.hpp b/wxdata/include/scwx/util/iterator.hpp index 9750a58a..59f70172 100644 --- a/wxdata/include/scwx/util/iterator.hpp +++ b/wxdata/include/scwx/util/iterator.hpp @@ -28,6 +28,11 @@ public: static const Iterator endIterator = ++Iterator(endValue); return endIterator; } + std::size_t count() + { + return static_cast(endValue) - static_cast(beginValue) + + 1; + } bool operator!=(const Iterator& i) { return value_ != i.value_; } };