Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to update existing bookmark #1306

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ MainWindow::MainWindow(const QString& cfgfile, bool edit_conf, QWidget *parent)

// Bookmarks
connect(uiDockBookmarks, SIGNAL(newBookmarkActivated(qint64, QString, int)), this, SLOT(onBookmarkActivated(qint64, QString, int)));
connect(uiDockBookmarks->actionUpdateBookmark, SIGNAL(triggered()), this, SLOT(on_actionUpdateBookmark_triggered()));
connect(uiDockBookmarks->actionAddBookmark, SIGNAL(triggered()), this, SLOT(on_actionAddBookmark_triggered()));
connect(&Bookmarks::Get(), SIGNAL(BookmarksChanged()), ui->plotter, SLOT(updateOverlay()));

Expand Down Expand Up @@ -2450,6 +2451,30 @@ void MainWindow::on_actionAboutQt_triggered()
QMessageBox::aboutQt(this, tr("About Qt"));
}

void MainWindow::on_actionUpdateBookmark_triggered()
{
auto* action = qobject_cast<QAction *>(sender());
if (!action)
{
return;
}
bool ok = false;
auto bookmarkIndex = action->data().toInt(&ok);
if (!ok)
{
return;
}
BookmarkInfo info;
info.frequency = ui->freqCtrl->getFrequency();
info.bandwidth = ui->plotter->getFilterBw();
info.modulation = uiDockRxOpt->currentDemodAsString();
auto newIndex = Bookmarks::Get().update(bookmarkIndex, info);
if (newIndex >= 0)
{
uiDockBookmarks->selectBookmark(newIndex);
}
}

void MainWindow::on_actionAddBookmark_triggered()
{
bool ok=false;
Expand Down
1 change: 1 addition & 0 deletions src/applications/gqrx/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ private slots:
void on_actionKbdShortcuts_triggered();
void on_actionAbout_triggered();
void on_actionAboutQt_triggered();
void on_actionUpdateBookmark_triggered();
void on_actionAddBookmark_triggered();
void on_actionDX_Cluster_triggered();

Expand Down
11 changes: 11 additions & 0 deletions src/qtgui/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ void Bookmarks::setConfigDir(const QString& cfg_dir)
std::cout << "BookmarksFile is " << m_bookmarksFile.toStdString() << std::endl;
}

int Bookmarks::update(int index, BookmarkInfo& info)
{
m_BookmarkList[index].frequency = info.frequency;
m_BookmarkList[index].bandwidth = info.bandwidth;
m_BookmarkList[index].modulation = info.modulation;
auto newInfo = m_BookmarkList[index];
std::stable_sort(m_BookmarkList.begin(),m_BookmarkList.end());
save();
return m_BookmarkList.indexOf(newInfo);
}

void Bookmarks::add(BookmarkInfo &info)
{
m_BookmarkList.append(info);
Expand Down
10 changes: 10 additions & 0 deletions src/qtgui/bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ struct BookmarkInfo
{
return frequency < other.frequency;
}

bool operator==(const BookmarkInfo &other) const
Copy link
Contributor

@willcode willcode Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used? In stable_sort or indexOff?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you edited. 😄 This is needed for indexOf.

{
return frequency == other.frequency
and name == other.name
and modulation == other.modulation
and bandwidth == other.bandwidth
and tags == other.tags;
}
/*
void setTags(QString tagString);
QString getTagString();
Expand All @@ -104,6 +113,7 @@ class Bookmarks : public QObject
static Bookmarks& Get();

void add(BookmarkInfo& info);
int update(int index, BookmarkInfo& info);
void remove(int index);
bool load();
bool save();
Expand Down
5 changes: 5 additions & 0 deletions src/qtgui/bookmarkstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,8 @@ int BookmarksTableModel::GetBookmarksIndexForRow(int iRow)
{
return m_mapRowToBookmarksIndex[iRow];
}

int BookmarksTableModel::GetRowForBookmarksIndex(int bookmarkIndex)
{
return m_mapRowToBookmarksIndex.key(bookmarkIndex, -1);
}
1 change: 1 addition & 0 deletions src/qtgui/bookmarkstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BookmarksTableModel : public QAbstractTableModel

BookmarkInfo* getBookmarkAtRow(int row);
int GetBookmarksIndexForRow(int iRow);
int GetRowForBookmarksIndex(int bookmarkIndex);

private:
QList<BookmarkInfo*> m_Bookmarks;
Expand Down
33 changes: 28 additions & 5 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ DockBookmarks::DockBookmarks(QWidget *parent) :

// Bookmarks Context menu
contextmenu = new QMenu(this);

//MenuItem Update
{
actionUpdateBookmark = new QAction("Update bookmark", this);
}
// MenuItem Delete
{
QAction* action = new QAction("Delete Bookmark", this);
contextmenu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(DeleteSelectedBookmark()));
actionDeleteBookmark = new QAction("Delete bookmark", this);
connect(actionDeleteBookmark, SIGNAL(triggered()), this, SLOT(DeleteSelectedBookmark()));
}
// MenuItem Add
{
actionAddBookmark = new QAction("Add Bookmark", this);
contextmenu->addAction(actionAddBookmark);
actionAddBookmark = new QAction("Add new bookmark", this);
}
ui->tableViewFrequencyList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableViewFrequencyList, SIGNAL(customContextMenuRequested(const QPoint&)),
Expand Down Expand Up @@ -189,6 +192,17 @@ bool DockBookmarks::DeleteSelectedBookmark()

void DockBookmarks::ShowContextMenu(const QPoint& pos)
{
contextmenu->clear();
auto bookmark = ui->tableViewFrequencyList->indexAt(pos);
if (bookmark != QModelIndex())
{
auto bookmarkIndex = bookmarksTableModel->GetBookmarksIndexForRow(bookmark.row());
actionUpdateBookmark->setData(QVariant::fromValue(bookmarkIndex));
contextmenu->addAction(actionUpdateBookmark);
contextmenu->addAction(actionDeleteBookmark);
contextmenu->addSeparator();
}
contextmenu->addAction(actionAddBookmark);
contextmenu->popup(ui->tableViewFrequencyList->viewport()->mapToGlobal(pos));
}

Expand Down Expand Up @@ -230,6 +244,15 @@ void ComboBoxDelegateModulation::setModelData(QWidget *editor, QAbstractItemMode
model->setData(index, comboBox->currentText(), Qt::EditRole);
}

void DockBookmarks::selectBookmark(int bookmarkIndex)
{
auto row = bookmarksTableModel->GetRowForBookmarksIndex(bookmarkIndex);
if (row >= 0)
{
ui->tableViewFrequencyList->selectRow(row);;
}
}

void DockBookmarks::changeBookmarkTags(int row, int /*column*/)
{
bool ok = false;
Expand Down
3 changes: 3 additions & 0 deletions src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ class DockBookmarks : public QDockWidget

// ui->tableViewFrequencyList
// ui->tableWidgetTagList
QAction* actionUpdateBookmark;
QAction* actionDeleteBookmark;
QAction* actionAddBookmark;

void updateTags();
void updateBookmarks();
void changeBookmarkTags(int row, int /*column*/);
void selectBookmark(int bookmarkIndex);

signals:
void newBookmarkActivated(qint64, QString, int);
Expand Down