mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-23 12:18:37 -05:00
Better group/sort handling; sets don't like duplicate compares.
This commit is contained in:
parent
73954055e6
commit
cc8c992123
@ -22,13 +22,15 @@ void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
|
|||||||
|
|
||||||
wxGetApp().getDemodMgr().saveInstance(be->node, demod);
|
wxGetApp().getDemodMgr().saveInstance(be->node, demod);
|
||||||
|
|
||||||
bmData[group].insert(be);
|
bmData[group].push_back(be);
|
||||||
|
bmDataSorted[group] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
|
void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
|
||||||
std::lock_guard < std::mutex > lock(busy_lock);
|
std::lock_guard < std::mutex > lock(busy_lock);
|
||||||
|
|
||||||
bmData[group].insert(be);
|
bmData[group].push_back(be);
|
||||||
|
bmDataSorted[group] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +38,15 @@ void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) {
|
|||||||
std::lock_guard < std::mutex > lockData(busy_lock);
|
std::lock_guard < std::mutex > lockData(busy_lock);
|
||||||
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
|
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
|
||||||
|
|
||||||
bmData[group].erase(be);
|
if (bmData.find(group) == bmData.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BookmarkList::iterator i = std::find(bmData[group].begin(), bmData[group].end(), be);
|
||||||
|
|
||||||
|
if (i != bmData[group].end()) {
|
||||||
|
bmData[group].erase(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
|
void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
|
||||||
@ -44,8 +54,9 @@ void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
|
|||||||
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
|
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
|
||||||
|
|
||||||
for (auto &bmd_i : bmData) {
|
for (auto &bmd_i : bmData) {
|
||||||
if (bmd_i.second.find(be) != bmd_i.second.end()) {
|
BookmarkList::iterator i = std::find(bmd_i.second.begin(), bmd_i.second.end(), be);
|
||||||
bmd_i.second.erase(be);
|
if (i != bmd_i.second.end()) {
|
||||||
|
bmd_i.second.erase(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,25 +65,23 @@ void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
|
|||||||
BookmarkList BookmarkMgr::getBookmarks(std::string group) {
|
BookmarkList BookmarkMgr::getBookmarks(std::string group) {
|
||||||
std::lock_guard < std::mutex > lock(busy_lock);
|
std::lock_guard < std::mutex > lock(busy_lock);
|
||||||
|
|
||||||
BookmarkList results;
|
if (bmData.find(group) == bmData.end()) {
|
||||||
|
BookmarkList results;
|
||||||
for (auto be_i : bmData[group]) {
|
return results;
|
||||||
results.push_back(be_i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
if (!bmDataSorted[group]) {
|
||||||
}
|
std::sort(bmData[group].begin(), bmData[group].end(), BookmarkEntryCompare());
|
||||||
|
bmDataSorted[group] = true;
|
||||||
|
}
|
||||||
|
|
||||||
BookmarkGroup BookmarkMgr::getGroup(std::string group) {
|
|
||||||
return bmData[group];
|
return bmData[group];
|
||||||
}
|
}
|
||||||
|
|
||||||
BookmarkNames BookmarkMgr::getGroups() {
|
void BookmarkMgr::getGroups(BookmarkNames &arr) {
|
||||||
BookmarkNames results;
|
|
||||||
for (BookmarkMap::iterator i = bmData.begin(); i!= bmData.end(); ++i) {
|
for (BookmarkMap::iterator i = bmData.begin(); i!= bmData.end(); ++i) {
|
||||||
results.push_back(i->first);
|
arr.push_back(i->first);
|
||||||
}
|
}
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkMgr::getGroups(wxArrayString &arr) {
|
void BookmarkMgr::getGroups(wxArrayString &arr) {
|
||||||
|
@ -31,8 +31,8 @@ struct BookmarkEntryCompare : public std::binary_function<BookmarkEntry *,Bookma
|
|||||||
|
|
||||||
|
|
||||||
typedef std::vector<BookmarkEntry *> BookmarkList;
|
typedef std::vector<BookmarkEntry *> BookmarkList;
|
||||||
typedef std::set<BookmarkEntry *, BookmarkEntryCompare> BookmarkGroup;
|
typedef std::map<std::string, BookmarkList > BookmarkMap;
|
||||||
typedef std::map<std::string, BookmarkGroup > BookmarkMap;
|
typedef std::map<std::string, bool > BookmarkMapSorted;
|
||||||
typedef std::vector<std::string> BookmarkNames;
|
typedef std::vector<std::string> BookmarkNames;
|
||||||
|
|
||||||
class BookmarkMgr {
|
class BookmarkMgr {
|
||||||
@ -46,9 +46,7 @@ public:
|
|||||||
void removeBookmark(BookmarkEntry *be);
|
void removeBookmark(BookmarkEntry *be);
|
||||||
|
|
||||||
BookmarkList getBookmarks(std::string group);
|
BookmarkList getBookmarks(std::string group);
|
||||||
|
void getGroups(BookmarkNames &arr);
|
||||||
BookmarkGroup getGroup(std::string group);
|
|
||||||
BookmarkNames getGroups();
|
|
||||||
void getGroups(wxArrayString &arr);
|
void getGroups(wxArrayString &arr);
|
||||||
|
|
||||||
void updateActiveList();
|
void updateActiveList();
|
||||||
@ -65,6 +63,7 @@ protected:
|
|||||||
BookmarkEntry *demodToBookmarkEntry(DemodulatorInstance *demod);
|
BookmarkEntry *demodToBookmarkEntry(DemodulatorInstance *demod);
|
||||||
|
|
||||||
BookmarkMap bmData;
|
BookmarkMap bmData;
|
||||||
|
BookmarkMapSorted bmDataSorted;
|
||||||
BookmarkList recents;
|
BookmarkList recents;
|
||||||
std::mutex busy_lock;
|
std::mutex busy_lock;
|
||||||
};
|
};
|
||||||
|
@ -92,10 +92,10 @@ void BookmarkView::updateBookmarks(std::string group) {
|
|||||||
|
|
||||||
|
|
||||||
wxTreeItemId BookmarkView::refreshBookmarks() {
|
wxTreeItemId BookmarkView::refreshBookmarks() {
|
||||||
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
|
||||||
if (!groupNames.size()) {
|
BookmarkNames groupNames;
|
||||||
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
wxGetApp().getBookmarkMgr().getGroups(groupNames);
|
||||||
}
|
|
||||||
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
|
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
|
||||||
doUpdateBookmarkGroup.erase(doUpdateBookmarkGroup.begin(), doUpdateBookmarkGroup.end());
|
doUpdateBookmarkGroup.erase(doUpdateBookmarkGroup.begin(), doUpdateBookmarkGroup.end());
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
|
|||||||
wxTreeItemId groupItem = groups[gn_i];
|
wxTreeItemId groupItem = groups[gn_i];
|
||||||
m_treeView->DeleteChildren(groupItem);
|
m_treeView->DeleteChildren(groupItem);
|
||||||
|
|
||||||
BookmarkGroup bmList = wxGetApp().getBookmarkMgr().getGroup(gn_i);
|
BookmarkList bmList = wxGetApp().getBookmarkMgr().getBookmarks(gn_i);
|
||||||
for (auto bmEnt : bmList) {
|
for (auto bmEnt : bmList) {
|
||||||
TreeViewItem* tvi = new TreeViewItem();
|
TreeViewItem* tvi = new TreeViewItem();
|
||||||
tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK;
|
tvi->type = TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK;
|
||||||
@ -626,7 +626,7 @@ void BookmarkView::onActivateRecent( wxCommandEvent& event ) {
|
|||||||
void BookmarkView::onAddGroup( wxCommandEvent& event ) {
|
void BookmarkView::onAddGroup( wxCommandEvent& event ) {
|
||||||
wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", "");
|
wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", "");
|
||||||
if (stringVal.ToStdString() != "") {
|
if (stringVal.ToStdString() != "") {
|
||||||
wxGetApp().getBookmarkMgr().getGroup(stringVal.ToStdString());
|
wxGetApp().getBookmarkMgr().getBookmarks(stringVal.ToStdString());
|
||||||
wxGetApp().getBookmarkMgr().updateBookmarks();
|
wxGetApp().getBookmarkMgr().updateBookmarks();
|
||||||
groupSel = stringVal;
|
groupSel = stringVal;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user