From 3d324b9158e91b863d2e50f15dc5a7d5de42c366 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Alves Cruz Date: Tue, 18 Jun 2024 03:29:52 -0300 Subject: [PATCH] fix: sonar cloud issues --- source/palette_brushlist.cpp | 14 +++---- source/palette_brushlist.h | 8 ++-- source/palette_window.cpp | 72 +++++++++++++++++++----------------- source/palette_window.h | 5 ++- 4 files changed, 54 insertions(+), 45 deletions(-) diff --git a/source/palette_brushlist.cpp b/source/palette_brushlist.cpp index 3df77c84..d8244c81 100644 --- a/source/palette_brushlist.cpp +++ b/source/palette_brushlist.cpp @@ -160,13 +160,13 @@ bool BrushPalettePanel::SelectBrush(const Brush* whatBrush) { } if (panel->SelectBrush(whatBrush)) { - for (const auto &palettePanel : tool_bars) { + for (const auto palettePanel : tool_bars) { palettePanel->SelectBrush(nullptr); } return true; } - for (const auto &palettePanel : tool_bars) { + for (const auto palettePanel : tool_bars) { if (palettePanel->SelectBrush(whatBrush)) { panel->SelectBrush(nullptr); return true; @@ -181,7 +181,7 @@ bool BrushPalettePanel::SelectBrush(const Brush* whatBrush) { panel = dynamic_cast(choicebook->GetPage(pageIndex)); if (panel && panel->SelectBrush(whatBrush)) { choicebook->ChangeSelection(pageIndex); - for (const auto &palettePanel : tool_bars) { + for (const auto palettePanel : tool_bars) { palettePanel->SelectBrush(nullptr); } return true; @@ -357,7 +357,7 @@ bool BrushPanel::SelectBrush(const Brush* whatBrush) { return brushbox->SelectBrush(whatBrush); } - for (const auto &brush : tileset->brushlist) { + for (const auto brush : tileset->brushlist) { if (brush == whatBrush) { LoadContents(); return brushbox->SelectBrush(whatBrush); @@ -380,7 +380,7 @@ void BrushPanel::OnClickListBoxRow(wxCommandEvent &event) { ASSERT(brushbox); const auto index = event.GetSelection(); - if (const auto &paletteWindow = g_gui.GetParentWindowByType(this); paletteWindow != nullptr) { + if (const auto paletteWindow = g_gui.GetParentWindowByType(this); paletteWindow != nullptr) { g_gui.ActivatePalette(paletteWindow); } @@ -410,7 +410,7 @@ BrushIconBox::BrushIconBox(wxWindow* parent, const TilesetCategory* tileset, Ren auto rowsizer = newd wxBoxSizer(wxHORIZONTAL); - for (const auto &brush : tileset->brushlist) { + for (const auto brush : tileset->brushlist) { const auto brushButton = newd BrushButton(this, brush, rsz); rowsizer->Add(brushButton); brushButtons.emplace_back(brushButton); @@ -448,7 +448,7 @@ bool BrushIconBox::SelectBrush(const Brush* whatBrush) { return false; } - const auto &it = std::ranges::find_if(brushButtons.begin(), brushButtons.end(), [&](const auto &brushButton) { + const auto it = std::ranges::find_if(brushButtons.begin(), brushButtons.end(), [&](const auto brushButton) { return brushButton->brush == whatBrush; }); diff --git a/source/palette_brushlist.h b/source/palette_brushlist.h index f00e4a75..99fb57bf 100644 --- a/source/palette_brushlist.h +++ b/source/palette_brushlist.h @@ -60,7 +60,7 @@ class BrushBoxInterface { class BrushListBox : public wxVListBox, public BrushBoxInterface { public: BrushListBox(wxWindow* parent, const TilesetCategory* tileset); - ~BrushListBox() = default; + ~BrushListBox() final = default; wxWindow* GetSelfWindow() { return this; @@ -129,7 +129,7 @@ class BrushIconBox : public wxScrolledWindow, public BrushBoxInterface { class BrushPanel : public wxPanel { public: BrushPanel(wxWindow* parent, const TilesetCategory* tileset); - ~BrushPanel() = default; + ~BrushPanel() final = default; // Interface // Flushes this panel and consequent views will feature reloaded data @@ -171,7 +171,7 @@ class BrushPanel : public wxPanel { class BrushPalettePanel : public PalettePanel { public: BrushPalettePanel(wxWindow* parent, const TilesetContainer &tilesets, TilesetCategoryType category, wxWindowID id = wxID_ANY); - ~BrushPalettePanel() = default; + ~BrushPalettePanel() final = default; void AddTilesetEditor(wxSizer* sizer); @@ -194,7 +194,7 @@ class BrushPalettePanel : public PalettePanel { // Returns the currently selected brush (first brush if panel is not loaded) Brush* GetSelectedBrush() const; // Select the brush in the parameter, this only changes the look of the panel - bool SelectBrush(const Brush* whatBrush); + bool SelectBrush(const Brush* whatBrush) override; // Called when this page is displayed void OnSwitchIn(); diff --git a/source/palette_window.cpp b/source/palette_window.cpp index c6b10022..4e357f11 100644 --- a/source/palette_window.cpp +++ b/source/palette_window.cpp @@ -167,6 +167,22 @@ PalettePanel* PaletteWindow::CreateRAWPalette(wxWindow* parent, const TilesetCon return panel; } +bool PaletteWindow::CanSelectHouseBrush(PalettePanel* palette, const Brush* whatBrush) { + if (!palette || !whatBrush->isHouse()) { + return false; + } + + return true; +} + +bool PaletteWindow::CanSelectBrush(PalettePanel* palette, const Brush* whatBrush) { + if (!palette) { + return false; + } + + return palette->SelectBrush(whatBrush); +} + void PaletteWindow::ReloadSettings(Map* map) { if (terrainPalette) { terrainPalette->SetListType(wxstr(g_settings.getString(Config::PALETTE_TERRAIN_STYLE))); @@ -197,7 +213,7 @@ void PaletteWindow::ReloadSettings(Map* map) { InvalidateContents(); } -void PaletteWindow::LoadCurrentContents() { +void PaletteWindow::LoadCurrentContents() const { if (!choicebook) { return; } @@ -312,7 +328,7 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) { return false; } - if (whatBrush->isHouse() && housePalette) { + if (CanSelectHouseBrush(housePalette, whatBrush)) { housePalette->SelectBrush(whatBrush); SelectPage(TILESET_HOUSE); return true; @@ -325,35 +341,35 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) { } case TILESET_DOODAD: { // Ok, search doodad before terrain - if (doodadPalette && doodadPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(doodadPalette, whatBrush)) { SelectPage(TILESET_DOODAD); return true; } break; } case TILESET_ITEM: { - if (itemPalette && itemPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(itemPalette, whatBrush)) { SelectPage(TILESET_ITEM); return true; } break; } case TILESET_MONSTER: { - if (monsterPalette && monsterPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(monsterPalette, whatBrush)) { SelectPage(TILESET_MONSTER); return true; } break; } case TILESET_NPC: { - if (npcPalette && npcPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(npcPalette, whatBrush)) { SelectPage(TILESET_NPC); return true; } break; } case TILESET_RAW: { - if (rawPalette && rawPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(rawPalette, whatBrush)) { SelectPage(TILESET_RAW); return true; } @@ -364,49 +380,39 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) { } // Test if it's a terrain brush - if (terrainPalette && terrainPalette->SelectBrush(whatBrush)) { + if (CanSelectBrush(terrainPalette, whatBrush)) { SelectPage(TILESET_TERRAIN); return true; } // Test if it's a doodad brush - if (primary != TILESET_DOODAD) { - if (doodadPalette && doodadPalette->SelectBrush(whatBrush)) { - SelectPage(TILESET_DOODAD); - return true; - } + if (primary != TILESET_DOODAD && CanSelectBrush(doodadPalette, whatBrush)) { + SelectPage(TILESET_DOODAD); + return true; } // Test if it's an item brush - if (primary != TILESET_ITEM) { - if (itemPalette && itemPalette->SelectBrush(whatBrush)) { - SelectPage(TILESET_ITEM); - return true; - } + if (primary != TILESET_ITEM && CanSelectBrush(itemPalette, whatBrush)) { + SelectPage(TILESET_ITEM); + return true; } // Test if it's a monster brush - if (primary != TILESET_MONSTER) { - if (monsterPalette && monsterPalette->SelectBrush(whatBrush)) { - SelectPage(TILESET_MONSTER); - return true; - } + if (primary != TILESET_MONSTER && CanSelectBrush(monsterPalette, whatBrush)) { + SelectPage(TILESET_MONSTER); + return true; } // Test if it's a npc brush - if (primary != TILESET_NPC) { - if (npcPalette && npcPalette->SelectBrush(whatBrush)) { - SelectPage(TILESET_NPC); - return true; - } + if (primary != TILESET_NPC && CanSelectBrush(npcPalette, whatBrush)) { + SelectPage(TILESET_NPC); + return true; } // Test if it's a raw brush - if (primary != TILESET_RAW) { - if (rawPalette && rawPalette->SelectBrush(whatBrush)) { - SelectPage(TILESET_RAW); - return true; - } + if (primary != TILESET_RAW && CanSelectBrush(rawPalette, whatBrush)) { + SelectPage(TILESET_RAW); + return true; } return false; diff --git a/source/palette_window.h b/source/palette_window.h index c3e65cb7..caadff0b 100644 --- a/source/palette_window.h +++ b/source/palette_window.h @@ -38,7 +38,7 @@ class PaletteWindow : public wxPanel { // Flushes all pages and forces them to be reloaded from the palette data again void InvalidateContents(); // (Re)Loads all currently displayed data, called from InvalidateContents implicitly - void LoadCurrentContents(); + void LoadCurrentContents() const; // Goes to the selected page and selects any brush there void SelectPage(PaletteType palette); // The currently selected brush in this palette @@ -78,6 +78,9 @@ class PaletteWindow : public wxPanel { static PalettePanel* CreateZonesPalette(wxWindow* parent, const TilesetContainer &tilesets); static PalettePanel* CreateRAWPalette(wxWindow* parent, const TilesetContainer &tilesets); + static bool CanSelectHouseBrush(PalettePanel* palette, const Brush* whatBrush); + static bool CanSelectBrush(PalettePanel* palette, const Brush* whatBrush); + wxChoicebook* choicebook = newd wxChoicebook(this, PALETTE_CHOICEBOOK, wxDefaultPosition, wxSize(230, 250)); BrushPalettePanel* terrainPalette = nullptr;