diff --git a/src/ui/viewmodels/AssetListViewModel.cpp b/src/ui/viewmodels/AssetListViewModel.cpp index a7df1fa6..f57857ad 100644 --- a/src/ui/viewmodels/AssetListViewModel.cpp +++ b/src/ui/viewmodels/AssetListViewModel.cpp @@ -491,6 +491,22 @@ void AssetListViewModel::AddOrRemoveFilteredItem(gsl::index nAssetIndex) } } +void AssetListViewModel::SyncAsset(AssetSummaryViewModel& vmSummary, const ra::data::models::AssetModelBase& pAsset) +{ + vmSummary.SetLabel(pAsset.GetName()); + vmSummary.SetType(pAsset.GetType()); + vmSummary.SetCategory(pAsset.GetCategory()); + vmSummary.SetChanges(pAsset.GetChanges()); + vmSummary.SetState(pAsset.GetState()); + vmSummary.SetWarning(pAsset.GetValidationError()); + + const auto* pAchievement = dynamic_cast(&pAsset); + if (pAchievement != nullptr) + vmSummary.SetPoints(pAchievement->GetPoints()); + else + vmSummary.SetPoints(0); +} + bool AssetListViewModel::AddOrRemoveFilteredItem(const ra::data::models::AssetModelBase& pAsset) { const auto nIndex = GetFilteredAssetIndex(pAsset); @@ -501,22 +517,15 @@ bool AssetListViewModel::AddOrRemoveFilteredItem(const ra::data::models::AssetMo { auto pSummary = std::make_unique(); pSummary->SetId(ra::to_signed(pAsset.GetID())); - pSummary->SetLabel(pAsset.GetName()); - pSummary->SetType(pAsset.GetType()); - pSummary->SetCategory(pAsset.GetCategory()); - pSummary->SetChanges(pAsset.GetChanges()); - pSummary->SetState(pAsset.GetState()); - pSummary->SetWarning(pAsset.GetValidationError()); - - const auto* pAchievement = dynamic_cast(&pAsset); - if (pAchievement != nullptr) - pSummary->SetPoints(pAchievement->GetPoints()); - else - pSummary->SetPoints(0); + SyncAsset(*pSummary, pAsset); m_vFilteredAssets.Append(std::move(pSummary)); return true; } + else + { + SyncAsset(*m_vFilteredAssets.GetItemAt(nIndex), pAsset); + } } else { diff --git a/src/ui/viewmodels/AssetListViewModel.hh b/src/ui/viewmodels/AssetListViewModel.hh index 14c3e1b8..d307aa54 100644 --- a/src/ui/viewmodels/AssetListViewModel.hh +++ b/src/ui/viewmodels/AssetListViewModel.hh @@ -312,6 +312,7 @@ private: bool MatchesFilter(const ra::data::models::AssetModelBase& pAsset) const; void AddOrRemoveFilteredItem(gsl::index nAssetIndex); bool AddOrRemoveFilteredItem(const ra::data::models::AssetModelBase& pAsset); + static void SyncAsset(AssetSummaryViewModel& vmSummary, const ra::data::models::AssetModelBase& pAsset); gsl::index GetFilteredAssetIndex(const ra::data::models::AssetModelBase& pAsset) const; void ApplyFilter(); diff --git a/src/ui/win32/FileDialog.cpp b/src/ui/win32/FileDialog.cpp index 5a760d86..336e9e34 100644 --- a/src/ui/win32/FileDialog.cpp +++ b/src/ui/win32/FileDialog.cpp @@ -144,7 +144,7 @@ static void ShowFolder(FileDialogViewModel& vmFileDialog, HWND hParentWnd) void FileDialog::Presenter::DoShowModal(ra::ui::WindowViewModelBase& oViewModel, HWND hParentWnd) { - auto& vmFileDialog = reinterpret_cast(oViewModel); + auto& vmFileDialog = dynamic_cast(oViewModel); if (vmFileDialog.GetMode() == FileDialogViewModel::Mode::Folder) { diff --git a/src/ui/win32/MessageBoxDialog.cpp b/src/ui/win32/MessageBoxDialog.cpp index de82d64e..e32f4c03 100644 --- a/src/ui/win32/MessageBoxDialog.cpp +++ b/src/ui/win32/MessageBoxDialog.cpp @@ -43,7 +43,7 @@ void MessageBoxDialog::Presenter::ShowModal(ra::ui::WindowViewModelBase& oViewMo void MessageBoxDialog::Presenter::DoShowModal(ra::ui::WindowViewModelBase& oViewModel, HWND hParentWnd) { - auto& oMessageBoxViewModel = reinterpret_cast(oViewModel); + auto& oMessageBoxViewModel = dynamic_cast(oViewModel); int nButton = 0; if (pTaskDialog == nullptr || oMessageBoxViewModel.GetHeader().empty()) diff --git a/src/ui/win32/OverlaySettingsDialog.cpp b/src/ui/win32/OverlaySettingsDialog.cpp index 0105c14d..38d752c5 100644 --- a/src/ui/win32/OverlaySettingsDialog.cpp +++ b/src/ui/win32/OverlaySettingsDialog.cpp @@ -14,7 +14,7 @@ bool OverlaySettingsDialog::Presenter::IsSupported(const ra::ui::WindowViewModel void OverlaySettingsDialog::Presenter::ShowModal(ra::ui::WindowViewModelBase& vmViewModel, HWND hParentWnd) { - auto& vmSettings = reinterpret_cast(vmViewModel); + auto& vmSettings = dynamic_cast(vmViewModel); OverlaySettingsDialog oDialog(vmSettings); oDialog.CreateModalWindow(MAKEINTRESOURCE(IDD_RA_OVERLAYSETTINGS), this, hParentWnd); @@ -96,7 +96,7 @@ BOOL OverlaySettingsDialog::OnCommand(WORD nCommand) { if (nCommand == IDC_RA_BROWSE) { - auto& vmSettings = reinterpret_cast(m_vmWindow); + auto& vmSettings = dynamic_cast(m_vmWindow); vmSettings.BrowseLocation(); return TRUE; } diff --git a/src/ui/win32/bindings/ComboBoxBinding.hh b/src/ui/win32/bindings/ComboBoxBinding.hh index 44771a70..8e1b09d7 100644 --- a/src/ui/win32/bindings/ComboBoxBinding.hh +++ b/src/ui/win32/bindings/ComboBoxBinding.hh @@ -64,7 +64,10 @@ public: void BindItems(ViewModelCollectionBase& pViewModels, const IntModelProperty& pIdProperty, const StringModelProperty& pTextProperty) { +#pragma warning(push) +#pragma warning(disable : 26465) // const_cast forces a call to the const implementation BindItems(const_cast(pViewModels), pIdProperty, pTextProperty); +#pragma warning(pop) m_pMutableViewModelCollection = &pViewModels; pViewModels.AddNotifyTarget(*this);