diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 13:24:16 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 21:23:10 +0100 |
commit | 306ad2effe4d0897453e61ad787e01dc47c33076 (patch) | |
tree | 75b8b291af55e80d01d9eb85afd7d465233a1a57 /src/gui/widgets/tabbedarea.cpp | |
parent | 66599a9896e0cf69b58c0a73152aba4750d87af2 (diff) | |
download | mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.gz mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.bz2 mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.xz mana-306ad2effe4d0897453e61ad787e01dc47c33076.zip |
General code cleanups
* Use default member initializers
* Use range-based for loops
* Avoid needless pointer references for ShopItem::mDuplicates
* Removed type aliases that are only used once or twice
* Removed more unused includes
* Removed some unused functions
* Removed superfluous .c_str()
* Rely on default copy and assignment operators for Vector class
* Use std::unique_ptr in some places
* Removed duplicated mPlayerMoney updating in SellDialog
* Removed duplicated Game::handleInput call
* Removed unused SDLInput::mMouseInWindow
* Removed remnant of manual widget positioning in HelpWindow
* Removed superfluous initialization of static pointers
Diffstat (limited to 'src/gui/widgets/tabbedarea.cpp')
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 644adf07..772a8e22 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -48,10 +48,10 @@ int TabbedArea::getNumberOfTabs() const Tab *TabbedArea::getTab(const std::string &name) const { - for (auto itr = mTabs.begin(); itr != mTabs.end(); ++itr) + for (const auto &[tab, _] : mTabs) { - if ((*itr).first->getCaption() == name) - return static_cast<Tab*>((*itr).first); + if (tab->getCaption() == name) + return static_cast<Tab*>(tab); } return nullptr; } @@ -113,8 +113,7 @@ void TabbedArea::removeTab(Tab *tab) mSelectedTab = nullptr; } - TabContainer::iterator iter; - for (iter = mTabs.begin(); iter != mTabs.end(); iter++) + for (auto iter = mTabs.begin(); iter != mTabs.end(); iter++) { if (iter->first == tab) { @@ -124,12 +123,11 @@ void TabbedArea::removeTab(Tab *tab) } } - std::vector<gcn::Tab*>::iterator iter2; - for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) + for (auto iter = mTabsToDelete.begin(); iter != mTabsToDelete.end(); iter++) { - if (*iter2 == tab) + if (*iter == tab) { - mTabsToDelete.erase(iter2); + mTabsToDelete.erase(iter); delete tab; break; } @@ -154,9 +152,8 @@ void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent) { gcn::Widget *widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); - auto *tab = dynamic_cast<gcn::Tab*>(widget); - if (tab) + if (auto *tab = dynamic_cast<gcn::Tab*>(widget)) { setSelectedTab(tab); requestFocus(); @@ -205,9 +202,9 @@ void TabbedArea::widgetResized(const gcn::Event &event) void TabbedArea::updateTabsWidth() { mTabsWidth = 0; - for (const auto &tab : mTabs) + for (const auto &[tab, _] : mTabs) { - mTabsWidth += tab.first->getWidth(); + mTabsWidth += tab->getWidth(); } updateVisibleTabsWidth(); } @@ -255,10 +252,9 @@ void TabbedArea::adjustTabPositions() void TabbedArea::action(const gcn::ActionEvent& actionEvent) { - Widget* source = actionEvent.getSource(); - Tab* tab = dynamic_cast<Tab*>(source); + Widget *source = actionEvent.getSource(); - if (tab) + if (Tab *tab = dynamic_cast<Tab*>(source)) { setSelectedTab(tab); } |