From 296f7790f13d15b98987c5948a0ace42cb16a224 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 4 Apr 2021 22:15:10 -0400 Subject: [PATCH] Cleanup: bookmark mgr --- src/forms/Bookmark/BookmarkView.cpp | 145 +++++++++++++--------------- src/forms/Bookmark/BookmarkView.h | 89 +++++++++-------- 2 files changed, 109 insertions(+), 125 deletions(-) diff --git a/src/forms/Bookmark/BookmarkView.cpp b/src/forms/Bookmark/BookmarkView.cpp index ae6892e..32cd28b 100644 --- a/src/forms/Bookmark/BookmarkView.cpp +++ b/src/forms/Bookmark/BookmarkView.cpp @@ -5,7 +5,6 @@ #include #include -#include #include "BookmarkView.h" #include "CubicSDR.h" @@ -25,10 +24,10 @@ #define BOOKMARK_VIEW_STR_RENAME_GROUP "Rename Group" -BookmarkViewVisualDragItem::BookmarkViewVisualDragItem(wxString labelValue) : wxDialog(NULL, wxID_ANY, L"", wxPoint(20,20), wxSize(-1,-1), wxFRAME_TOOL_WINDOW | wxNO_BORDER | wxSTAY_ON_TOP | wxALL ) { +BookmarkViewVisualDragItem::BookmarkViewVisualDragItem(const wxString& labelValue) : wxDialog(nullptr, wxID_ANY, L"", wxPoint(20,20), wxSize(-1,-1), wxFRAME_TOOL_WINDOW | wxNO_BORDER | wxSTAY_ON_TOP | wxALL ) { - wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); - wxStaticText *label = new wxStaticText( this, wxID_ANY, labelValue, wxDefaultPosition, wxDefaultSize, wxEXPAND ); + auto *sizer = new wxBoxSizer(wxVERTICAL); + auto *label = new wxStaticText( this, wxID_ANY, labelValue, wxDefaultPosition, wxDefaultSize, wxEXPAND ); sizer->Add(label, 1, wxALL | wxEXPAND, 5); @@ -38,12 +37,12 @@ BookmarkViewVisualDragItem::BookmarkViewVisualDragItem(wxString labelValue) : wx class ActionDialogRemoveBookmark : public ActionDialog { public: - ActionDialogRemoveBookmark( BookmarkEntryPtr be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) { + explicit ActionDialogRemoveBookmark( BookmarkEntryPtr be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) { subject = be; m_questionText->SetLabelText(wxT("Are you sure you want to remove the bookmark\n '" + BookmarkMgr::getBookmarkEntryDisplayName(subject) + "'?")); } - void doClickOK() { + void doClickOK() override { wxGetApp().getBookmarkMgr().removeBookmark(subject); wxGetApp().getBookmarkMgr().updateBookmarks(); } @@ -54,12 +53,12 @@ private: class ActionDialogRemoveGroup : public ActionDialog { public: - ActionDialogRemoveGroup( std::string groupName ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Group?")) { + explicit ActionDialogRemoveGroup( std::string groupName ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Group?")) { subject = groupName; m_questionText->SetLabelText(wxT("Warning: Are you sure you want to remove the group\n '" + subject + "' AND ALL BOOKMARKS WITHIN IT?")); } - void doClickOK() { + void doClickOK() override { wxGetApp().getBookmarkMgr().removeGroup(subject); wxGetApp().getBookmarkMgr().updateBookmarks(); } @@ -71,7 +70,7 @@ private: class ActionDialogRemoveRange : public ActionDialog { public: - ActionDialogRemoveRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) { + explicit ActionDialogRemoveRange( const BookmarkRangeEntryPtr& rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) { subject = rangeEnt; std::wstring name = rangeEnt->label; @@ -85,7 +84,7 @@ public: m_questionText->SetLabelText(L"Are you sure you want to remove the range\n '" + name + L"'?"); } - void doClickOK() { + void doClickOK() override { wxGetApp().getBookmarkMgr().removeRange(subject); wxGetApp().getBookmarkMgr().updateActiveList(); } @@ -97,7 +96,7 @@ private: class ActionDialogUpdateRange : public ActionDialog { public: - ActionDialogUpdateRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) { + explicit ActionDialogUpdateRange( const BookmarkRangeEntryPtr& rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) { subject = rangeEnt; std::wstring name = rangeEnt->label; @@ -111,7 +110,7 @@ public: m_questionText->SetLabelText(L"Are you sure you want to update the range\n '" + name + L"' to the active range?"); } - void doClickOK() { + void doClickOK() override { BookmarkRangeEntryPtr ue = BookmarkView::makeActiveRangeEntry(); subject->freq = ue->freq; @@ -232,7 +231,7 @@ void BookmarkView::updateBookmarks() { } -void BookmarkView::updateBookmarks(std::string group) { +void BookmarkView::updateBookmarks(const std::string& group) { doUpdateBookmarkGroup.insert(group); doUpdateBookmarks.store(true); } @@ -241,7 +240,7 @@ bool BookmarkView::isKeywordMatch(std::wstring search_str, std::vectorGetSelection()); TreeViewItem* prevSelCopy = nullptr; - if (prevSel != NULL) { + if (prevSel != nullptr) { prevSelCopy = new TreeViewItem(*prevSel); } - BookmarkNames groupNames; - wxGetApp().getBookmarkMgr().getGroups(groupNames); + BookmarkNames groupNameList; + wxGetApp().getBookmarkMgr().getGroups(groupNameList); doUpdateBookmarkGroup.clear(); wxTreeItemId bmSelFound = nullptr; std::map groupExpandState; - bool searchState = (searchKeywords.size() != 0); + bool searchState = !searchKeywords.empty(); groups.clear(); @@ -277,8 +276,8 @@ wxTreeItemId BookmarkView::refreshBookmarks() { bool bmExpandState = expandState["bookmark"]; - for (auto gn_i : groupNames) { - TreeViewItem* tvi = new TreeViewItem(); + for (const auto& gn_i : groupNameList) { + auto* tvi = new TreeViewItem(); tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP; tvi->groupName = gn_i; wxTreeItemId group_itm = m_treeView->AppendItem(bookmarkBranch, gn_i); @@ -286,7 +285,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() { groups[gn_i] = group_itm; if (prevSelCopy != nullptr && prevSelCopy->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP && gn_i == prevSelCopy->groupName) { bmSelFound = group_itm; - } else if (nextGroup != "" && gn_i == nextGroup) { + } else if (!nextGroup.empty() && gn_i == nextGroup) { bmSelFound = group_itm; nextGroup = ""; } @@ -298,7 +297,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() { m_treeView->Collapse(bookmarkBranch); } - for (auto gn_i : groupNames) { + for (const auto& gn_i : groupNameList) { wxTreeItemId groupItem = groups[gn_i]; bool groupExpanded = searchState || wxGetApp().getBookmarkMgr().getExpandState(gn_i); @@ -324,7 +323,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() { } } - TreeViewItem* tvi = new TreeViewItem(); + auto* tvi = new TreeViewItem(); tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK; tvi->bookmarkEnt = bmEnt; tvi->groupName = gn_i; @@ -361,7 +360,7 @@ void BookmarkView::doUpdateActiveList() { TreeViewItem* prevSel = itemToTVI(m_treeView->GetSelection()); TreeViewItem* prevSelCopy = nullptr; - if (prevSel != NULL) { + if (prevSel != nullptr) { prevSelCopy = new TreeViewItem(*prevSel); } @@ -369,10 +368,10 @@ void BookmarkView::doUpdateActiveList() { m_treeView->DeleteChildren(activeBranch); bool activeExpandState = expandState["active"]; - bool searchState = (searchKeywords.size() != 0); + bool searchState = !searchKeywords.empty(); wxTreeItemId selItem = nullptr; - for (auto demod_i : demods) { + for (const auto& demod_i : demods) { wxString activeLabel = BookmarkMgr::getActiveDisplayName(demod_i); if (searchState) { @@ -392,7 +391,7 @@ void BookmarkView::doUpdateActiveList() { } } - TreeViewItem* tvi = new TreeViewItem(); + auto* tvi = new TreeViewItem(); tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE; tvi->demod = demod_i; @@ -407,7 +406,7 @@ void BookmarkView::doUpdateActiveList() { } } - bool rangeExpandState = searchState?false:expandState["range"]; + bool rangeExpandState = !searchState && expandState["range"]; //Ranges BookmarkRangeList bmRanges = wxGetApp().getBookmarkMgr().getRanges(); @@ -415,13 +414,13 @@ void BookmarkView::doUpdateActiveList() { m_treeView->DeleteChildren(rangeBranch); for (auto &re_i: bmRanges) { - TreeViewItem* tvi = new TreeViewItem(); + auto* tvi = new TreeViewItem(); tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE; tvi->rangeEnt = re_i; std::wstring labelVal = re_i->label; - if (labelVal == L"") { + if (labelVal.empty()) { std::string wstr = frequencyToStr(re_i->startFreq) + " - " + frequencyToStr(re_i->endFreq); labelVal = wxString(wstr).ToStdWstring(); @@ -446,20 +445,20 @@ void BookmarkView::doUpdateActiveList() { m_treeView->DeleteChildren(recentBranch); for (auto &bmr_i: bmRecents) { - TreeViewItem* tvi = new TreeViewItem(); + auto* tvi = new TreeViewItem(); tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT; tvi->bookmarkEnt = bmr_i; std::wstring labelVal; bmr_i->node->child("user_label")->element()->get(labelVal); - if (labelVal == L"") { + if (labelVal.empty()) { std::string str = frequencyToStr(bmr_i->frequency) + " " + bmr_i->type; labelVal = wxString(str).ToStdWstring(); } - if (searchKeywords.size()) { + if (!searchKeywords.empty()) { std::string freqStr = frequencyToStr(bmr_i->frequency); std::string bwStr = frequencyToStr(bmr_i->bandwidth); @@ -559,7 +558,7 @@ void BookmarkView::onKeyUp( wxKeyEvent& event ) { void BookmarkView::onTreeActivate( wxTreeEvent& event ) { wxTreeItemId itm = event.GetItem(); - TreeViewItem* tvi = dynamic_cast(m_treeView->GetItemData(itm)); + auto* tvi = dynamic_cast(m_treeView->GetItemData(itm)); if (tvi == nullptr) { event.Skip(); @@ -588,7 +587,7 @@ void BookmarkView::onTreeActivate( wxTreeEvent& event ) { void BookmarkView::onTreeCollapse( wxTreeEvent& event ) { - bool searchState = (searchKeywords.size() != 0); + bool searchState = !searchKeywords.empty(); if (searchState) { event.Skip(); @@ -618,7 +617,7 @@ void BookmarkView::onTreeCollapse( wxTreeEvent& event ) { void BookmarkView::onTreeExpanded( wxTreeEvent& event ) { - bool searchState = (searchKeywords.size() != 0); + bool searchState = !searchKeywords.empty(); if (searchState) { event.Skip(); @@ -651,7 +650,7 @@ void BookmarkView::onTreeItemMenu( wxTreeEvent& /* event */ ) { if (m_treeView->GetSelection() == bookmarkBranch) { wxMenu menu; menu.Append(wxCONTEXT_ADD_GROUP_ID, BOOKMARK_VIEW_STR_ADD_GROUP); - menu.Connect(wxCONTEXT_ADD_GROUP_ID, wxEVT_MENU, (wxObjectEventFunction)&BookmarkView::onMenuItem, nullptr, this); + menu.Connect(wxCONTEXT_ADD_GROUP_ID, wxEVT_MENU, wxCommandEventHandler(BookmarkView::onMenuItem), nullptr, this); PopupMenu(&menu); } } @@ -676,12 +675,12 @@ bool BookmarkView::isMouseInView() { } -bool BookmarkView::getExpandState(std::string branchName) { +bool BookmarkView::getExpandState(const std::string& branchName) { return expandState[branchName]; } -void BookmarkView::setExpandState(std::string branchName, bool state) { +void BookmarkView::setExpandState(const std::string& branchName, bool state) { expandState[branchName] = state; } @@ -741,29 +740,29 @@ void BookmarkView::refreshLayout() { } -wxButton *BookmarkView::makeButton(wxWindow * /* parent */, std::string labelVal, wxObjectEventFunction handler) { - wxButton *nButton = new wxButton( m_buttonPanel, wxID_ANY, labelVal); +wxButton *BookmarkView::makeButton(wxWindow * /* parent */, const std::string& labelVal, wxObjectEventFunction handler) { + auto *nButton = new wxButton( m_buttonPanel, wxID_ANY, labelVal); nButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, handler, nullptr, this); return nButton; } -wxButton *BookmarkView::addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler) { +wxButton *BookmarkView::addButton(wxWindow *parent, const std::string& labelVal, wxObjectEventFunction handler) { wxButton *nButton = makeButton(parent, labelVal, handler); parent->GetSizer()->Add( nButton, 0, wxEXPAND); return nButton; } -void BookmarkView::doBookmarkActive(std::string group, DemodulatorInstancePtr demod) { +void BookmarkView::doBookmarkActive(const std::string& group, const DemodulatorInstancePtr& demod) { wxGetApp().getBookmarkMgr().addBookmark(group, demod); wxGetApp().getBookmarkMgr().updateBookmarks(); } -void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntryPtr be) { +void BookmarkView::doBookmarkRecent(const std::string& group, const BookmarkEntryPtr& be) { wxGetApp().getBookmarkMgr().addBookmark(group, be); nextEnt = be; @@ -773,7 +772,7 @@ void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntryPtr be) { } -void BookmarkView::doMoveBookmark(BookmarkEntryPtr be, std::string group) { +void BookmarkView::doMoveBookmark(const BookmarkEntryPtr& be, const std::string& group) { wxGetApp().getBookmarkMgr().moveBookmark(be, group); nextEnt = be; wxGetApp().getBookmarkMgr().updateBookmarks(); @@ -781,14 +780,14 @@ void BookmarkView::doMoveBookmark(BookmarkEntryPtr be, std::string group) { } -void BookmarkView::doRemoveActive(DemodulatorInstancePtr demod) { +void BookmarkView::doRemoveActive(const DemodulatorInstancePtr& demod) { wxGetApp().getBookmarkMgr().removeActive(demod); wxGetApp().getBookmarkMgr().updateActiveList(); } -void BookmarkView::doRemoveRecent(BookmarkEntryPtr be) { +void BookmarkView::doRemoveRecent(const BookmarkEntryPtr& be) { wxGetApp().getBookmarkMgr().removeRecent(be); wxGetApp().getBookmarkMgr().updateActiveList(); } @@ -814,7 +813,7 @@ void BookmarkView::addBookmarkChoice(wxWindow *parent) { updateBookmarkChoices(); bookmarkChoice = new wxChoice(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, bookmarkChoices, wxEXPAND, wxDefaultValidator, "Bookmark"); bookmarkChoice->Select(0); - bookmarkChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction)&BookmarkView::onBookmarkChoice, nullptr, this); + bookmarkChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(BookmarkView::onBookmarkChoice), nullptr, this); parent->GetSizer()->Add(bookmarkChoice, 0, wxALL | wxEXPAND); } @@ -838,7 +837,7 @@ void BookmarkView::onBookmarkChoice( wxCommandEvent & /* event */ ) { stringVal = bookmarkChoices[sel]; } - if (stringVal == "") { + if (stringVal.empty()) { return; } @@ -855,7 +854,7 @@ void BookmarkView::onBookmarkChoice( wxCommandEvent & /* event */ ) { } } -void BookmarkView::activeSelection(DemodulatorInstancePtr dsel) { +void BookmarkView::activeSelection(const DemodulatorInstancePtr& dsel) { if (dsel == nullptr) { hideProps(); @@ -901,7 +900,7 @@ void BookmarkView::activeSelection(DemodulatorInstancePtr dsel) { } -void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) { +void BookmarkView::activateBookmark(const BookmarkEntryPtr& bmEnt) { wxTreeItemId selItem = m_treeView->GetSelection(); if (selItem) { @@ -942,7 +941,7 @@ void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) { } -void BookmarkView::activateRange(BookmarkRangeEntryPtr rangeEnt) { +void BookmarkView::activateRange(const BookmarkRangeEntryPtr& rangeEnt) { //the following oly works if rangeEnt->freq is the middle of [rangeEnt->startFreq ; rangeEnt->startFreq] wxGetApp().setFrequency(rangeEnt->freq); @@ -952,7 +951,7 @@ void BookmarkView::activateRange(BookmarkRangeEntryPtr rangeEnt) { } -void BookmarkView::bookmarkSelection(BookmarkEntryPtr bmSel) { +void BookmarkView::bookmarkSelection(const BookmarkEntryPtr& bmSel) { m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency)); m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth)); @@ -985,7 +984,7 @@ void BookmarkView::bookmarkSelection(BookmarkEntryPtr bmSel) { } -void BookmarkView::recentSelection(BookmarkEntryPtr bmSel) { +void BookmarkView::recentSelection(const BookmarkEntryPtr& bmSel) { m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency)); m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth)); @@ -1017,7 +1016,7 @@ void BookmarkView::recentSelection(BookmarkEntryPtr bmSel) { refreshLayout(); } -void BookmarkView::groupSelection(std::string groupName) { +void BookmarkView::groupSelection(const std::string& groupName) { clearButtons(); @@ -1037,7 +1036,7 @@ void BookmarkView::groupSelection(std::string groupName) { } -void BookmarkView::rangeSelection(BookmarkRangeEntryPtr re) { +void BookmarkView::rangeSelection(const BookmarkRangeEntryPtr& re) { clearButtons(); hideProps(false); @@ -1118,7 +1117,7 @@ void BookmarkView::onTreeSelect( wxTreeEvent& event ) { } wxTreeItemId itm = event.GetItem(); - TreeViewItem* tvi = dynamic_cast(m_treeView->GetItemData(itm)); + auto* tvi = dynamic_cast(m_treeView->GetItemData(itm)); if (!tvi) { @@ -1196,7 +1195,7 @@ void BookmarkView::onLabelText( wxCommandEvent& /* event */ ) { } else if (curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) { std::string newGroupName = m_labelText->GetValue().ToStdString(); - if (newGroupName != "" && newGroupName != curSel->groupName) { + if (!newGroupName.empty() && newGroupName != curSel->groupName) { wxGetApp().getBookmarkMgr().renameGroup(curSel->groupName, newGroupName); nextGroup = newGroupName; wxGetApp().getBookmarkMgr().updateBookmarks(); @@ -1313,8 +1312,7 @@ void BookmarkView::onRemoveRecent ( wxCommandEvent& /* event */ ) { //let removeRecent() + updateActiveList() refresh the tree //and delete the recent node properly... - wxGetApp().getBookmarkMgr().removeRecent(bookmarkEntToRemove); - wxGetApp().getBookmarkMgr().updateActiveList(); + doRemoveRecent(bookmarkEntToRemove); } } @@ -1326,7 +1324,7 @@ void BookmarkView::onClearRecents ( wxCommandEvent& /* event */ ) { void BookmarkView::onAddGroup( wxCommandEvent& /* event */ ) { wxString stringVal = wxGetTextFromUser(BOOKMARK_VIEW_STR_ADD_GROUP_DESC, BOOKMARK_VIEW_STR_ADD_GROUP, ""); - if (stringVal.ToStdString() != "") { + if (!stringVal.ToStdString().empty()) { wxGetApp().getBookmarkMgr().addGroup(stringVal.ToStdString()); wxGetApp().getBookmarkMgr().updateBookmarks(); } @@ -1375,7 +1373,7 @@ void BookmarkView::onRenameRange( wxCommandEvent& /* event */ ) { std::string newGroupName = stringVal.Trim().ToStdString(); - if (newGroupName != "") { + if (!newGroupName.empty()) { wxGetApp().getBookmarkMgr().renameGroup(curSel->groupName, newGroupName); wxGetApp().getBookmarkMgr().updateBookmarks(); } @@ -1481,7 +1479,7 @@ void BookmarkView::onTreeEndDrag( wxTreeEvent& event ) { return; } - if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) { + if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP || tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { // Active -> Group Item doBookmarkActive(tvi->groupName, dragItem->demod); } else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { // Recent -> Group Item @@ -1490,15 +1488,6 @@ void BookmarkView::onTreeEndDrag( wxTreeEvent& event ) { } else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { // Bookmark -> Group Item doMoveBookmark(dragItem->bookmarkEnt, tvi->groupName); } - } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { - if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { // Active -> Same Group - doBookmarkActive(tvi->groupName, dragItem->demod); - } else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { // Recent -> Same Group - doBookmarkRecent(tvi->groupName, dragItem->bookmarkEnt); - m_treeView->Delete(dragItemId); - } else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { // Bookmark -> Same Group - doMoveBookmark(dragItem->bookmarkEnt, tvi->groupName); - } } } @@ -1541,7 +1530,7 @@ void BookmarkView::onMotion( wxMouseEvent& event ) { event.Skip(); } -void BookmarkView::setStatusText(std::string statusText) { +void BookmarkView::setStatusText(const std::string& statusText) { //make tooltips active on the tree view. wxGetApp().getAppFrame()->setStatusText(m_treeView, statusText); } @@ -1599,10 +1588,10 @@ void BookmarkView::onSearchText( wxCommandEvent& /* event */ ) { } } - if (searchKeywords.size() != 0 && !m_clearSearchButton->IsShown()) { + if (!searchKeywords.empty() && !m_clearSearchButton->IsShown()) { m_clearSearchButton->Show(); refreshLayout(); - } else if (searchKeywords.size() == 0 && m_clearSearchButton->IsShown()) { + } else if (searchKeywords.empty() && m_clearSearchButton->IsShown()) { m_clearSearchButton->Hide(); refreshLayout(); } @@ -1641,10 +1630,8 @@ BookmarkRangeEntryPtr BookmarkView::makeActiveRangeEntry() { void BookmarkView::SetTreeItemData(const wxTreeItemId& item, wxTreeItemData *data) { TreeViewItem *itemData = itemToTVI(item); - if (itemData != NULL) { - //cleanup previous data, if any - delete itemData; - } + // cleanup previous data, if any + delete itemData; m_treeView->SetItemData(item, data); } diff --git a/src/forms/Bookmark/BookmarkView.h b/src/forms/Bookmark/BookmarkView.h index 1afbc24..07266c7 100644 --- a/src/forms/Bookmark/BookmarkView.h +++ b/src/forms/Bookmark/BookmarkView.h @@ -34,9 +34,7 @@ public: groupName = src.groupName; }; - virtual ~TreeViewItem() { - // - }; + ~TreeViewItem() override = default;; TreeViewItemType type; @@ -50,16 +48,16 @@ public: class BookmarkViewVisualDragItem : public wxDialog { public: - BookmarkViewVisualDragItem(wxString labelValue = L"Popup"); + explicit BookmarkViewVisualDragItem(const wxString& labelValue = L"Popup"); }; class BookmarkView : public BookmarkPanel { public: - BookmarkView( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1, -1 ), long style = wxTAB_TRAVERSAL ); + explicit BookmarkView( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1, -1 ), long style = wxTAB_TRAVERSAL ); - virtual ~BookmarkView(); + ~BookmarkView() override; //order an asynchronous refresh/rebuild of the whole tree, //will take effect at the next onUpdateTimer() occurence. @@ -68,7 +66,7 @@ public: //order asynchronous updates of the bookmarks, //will take effect at the next onUpdateTimer() occurence. void updateBookmarks(); - void updateBookmarks(std::string group); + void updateBookmarks(const std::string& group); bool isKeywordMatch(std::wstring str, std::vector &keywords); @@ -77,21 +75,21 @@ public: void onMenuItem(wxCommandEvent& event); bool isMouseInView(); - bool getExpandState(std::string branchName); - void setExpandState(std::string branchName, bool state); + bool getExpandState(const std::string& branchName); + void setExpandState(const std::string& branchName, bool state); static BookmarkRangeEntryPtr makeActiveRangeEntry(); protected: - void activeSelection(DemodulatorInstancePtr dsel); - void bookmarkSelection(BookmarkEntryPtr bmSel); - void rangeSelection(BookmarkRangeEntryPtr re); + void activeSelection(const DemodulatorInstancePtr& dsel); + void bookmarkSelection(const BookmarkEntryPtr& bmSel); + void rangeSelection(const BookmarkRangeEntryPtr& re); - void activateBookmark(BookmarkEntryPtr bmEnt); + void activateBookmark(const BookmarkEntryPtr& bmEnt); - void activateRange(BookmarkRangeEntryPtr rangeEnt); - void recentSelection(BookmarkEntryPtr bmSel); - void groupSelection(std::string groupName); + void activateRange(const BookmarkRangeEntryPtr& rangeEnt); + void recentSelection(const BookmarkEntryPtr& bmSel); + void groupSelection(const std::string& groupName); void bookmarkBranchSelection(); void recentBranchSelection(); void rangeBranchSelection(); @@ -101,45 +99,45 @@ protected: void hideProps(bool hidePanel = true); void showProps(); - void onUpdateTimer( wxTimerEvent& event ); + void onUpdateTimer( wxTimerEvent& event ) override; //refresh / rebuild the whole tree item immediatly void doUpdateActiveList(); - void onKeyUp( wxKeyEvent& event ); - void onTreeActivate( wxTreeEvent& event ); - void onTreeCollapse( wxTreeEvent& event ); - void onTreeExpanded( wxTreeEvent& event ); - void onTreeItemMenu( wxTreeEvent& event ); - void onTreeSelect( wxTreeEvent& event ); - void onTreeSelectChanging( wxTreeEvent& event ); - void onLabelKillFocus(wxFocusEvent& event ); - void onLabelText( wxCommandEvent& event ); - void onDoubleClickFreq( wxMouseEvent& event ); - void onDoubleClickBandwidth( wxMouseEvent& event ); - void onTreeBeginDrag( wxTreeEvent& event ); - void onTreeEndDrag( wxTreeEvent& event ); - void onTreeItemGetTooltip( wxTreeEvent& event ); - void onEnterWindow( wxMouseEvent& event ); - void onLeaveWindow( wxMouseEvent& event ); - void onMotion( wxMouseEvent& event ); + void onKeyUp( wxKeyEvent& event ) override; + void onTreeActivate( wxTreeEvent& event ) override; + void onTreeCollapse( wxTreeEvent& event ) override; + void onTreeExpanded( wxTreeEvent& event ) override; + void onTreeItemMenu( wxTreeEvent& event ) override; + void onTreeSelect( wxTreeEvent& event ) override; + void onTreeSelectChanging( wxTreeEvent& event ) override; + void onLabelKillFocus(wxFocusEvent& event ) override; + void onLabelText( wxCommandEvent& event ) override; + void onDoubleClickFreq( wxMouseEvent& event ) override; + void onDoubleClickBandwidth( wxMouseEvent& event ) override; + void onTreeBeginDrag( wxTreeEvent& event ) override; + void onTreeEndDrag( wxTreeEvent& event ) override; + void onTreeItemGetTooltip( wxTreeEvent& event ) override; + void onEnterWindow( wxMouseEvent& event ) override; + void onLeaveWindow( wxMouseEvent& event ) override; + void onMotion( wxMouseEvent& event ) override; - void onSearchTextFocus( wxMouseEvent& event ); - void onSearchText( wxCommandEvent& event ); - void onClearSearch( wxCommandEvent& event ); + void onSearchTextFocus( wxMouseEvent& event ) override; + void onSearchText( wxCommandEvent& event ) override; + void onClearSearch( wxCommandEvent& event ) override; void clearButtons(); void showButtons(); void refreshLayout(); - wxButton *makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler); - wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler); + wxButton *makeButton(wxWindow *parent, const std::string& labelVal, wxObjectEventFunction handler); + wxButton *addButton(wxWindow *parent, const std::string& labelVal, wxObjectEventFunction handler); - void doBookmarkActive(std::string group, DemodulatorInstancePtr demod); - void doBookmarkRecent(std::string group, BookmarkEntryPtr be); - void doMoveBookmark(BookmarkEntryPtr be, std::string group); - void doRemoveActive(DemodulatorInstancePtr demod); - void doRemoveRecent(BookmarkEntryPtr be); + void doBookmarkActive(const std::string& group, const DemodulatorInstancePtr& demod); + void doBookmarkRecent(const std::string& group, const BookmarkEntryPtr& be); + void doMoveBookmark(const BookmarkEntryPtr& be, const std::string& group); + void doRemoveActive(const DemodulatorInstancePtr& demod); + void doRemoveRecent(const BookmarkEntryPtr& be); void doClearRecents(); void updateBookmarkChoices(); @@ -184,7 +182,6 @@ protected: // Bookmarks std::atomic_bool doUpdateBookmarks; std::set< std::string > doUpdateBookmarkGroup; - BookmarkNames groupNames; std::map groups; wxArrayString bookmarkChoices; wxChoice *bookmarkChoice; @@ -201,6 +198,6 @@ protected: // Search std::vector searchKeywords; - void setStatusText(std::string statusText); + void setStatusText(const std::string& statusText); };