Skip to content

Commit

Permalink
bookmarks: Support tag renaming
Browse files Browse the repository at this point in the history
Support tag renaming in all 3 places: new bookmark dialog, bookmark tags
dialog and tag selection list in a bookmarks dock.
Immediately update tags/bookmarks everywhere when tag name/color is
changed.
Prevent renaming "Untagged" tag and accidental creation of duplicate tags by
renaming.
  • Loading branch information
vladisslav2011 committed Feb 4, 2025
1 parent 37ef2c0 commit 34d5cb0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,8 @@ void MainWindow::on_actionAddBookmark_triggered()
mainLayout->addWidget(buttonCreateTag);
mainLayout->addWidget(taglist);
mainLayout->addWidget(buttonBox);
connect(taglist, SIGNAL(itemChanged(QTableWidgetItem *)), uiDockBookmarks, SLOT(dialog_tableWidgetTagList_itemChanged(QTableWidgetItem *)));
connect(taglist, SIGNAL(colorChanged()), uiDockBookmarks, SLOT(dialog_tableWidgetTagList_colorChanged()));

ok = dialog.exec();
if (ok)
Expand Down
4 changes: 2 additions & 2 deletions src/qtgui/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ bool Bookmarks::removeTag(QString tagName)
bool Bookmarks::setTagChecked(QString tagName, bool bChecked)
{
int idx = getTagIndex(tagName);
if (idx == -1) return false;
m_TagList[idx]->active = bChecked;
if (idx != -1)
m_TagList[idx]->active = bChecked;
emit BookmarksChanged();
emit TagListChanged();
return true;
Expand Down
40 changes: 25 additions & 15 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,18 @@ BookmarksTagList::BookmarksTagList(QWidget *parent, bool bShowUntagged )
{
connect(this, SIGNAL(cellClicked(int,int)),
this, SLOT(on_cellClicked(int,int)));
connect(this, SIGNAL(cellDoubleClicked(int,int)),
this, SLOT(on_cellDoubleClicked(int,int)));

// right click menu
popupMenu=new QMenu(this);

// Rename currently does not work.
// The problem is that after the tag name is changed in GUI
// you can not find the right TagInfo because you dont know
// the old tag name.
#if 0
// MenuItem "Rename"
{
QAction* actionRename = new QAction("Rename", this);
popupMenu->addAction(actionRename);
connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag()));
}
#endif

// MenuItem "Create new Tag"
{
Expand Down Expand Up @@ -104,6 +100,14 @@ void BookmarksTagList::on_cellClicked(int row, int column)
}
}

void BookmarksTagList::on_cellDoubleClicked(int row, int column)
{
if(column==1)
{
toggleCheckedState(row, column);
}
}

void BookmarksTagList::changeColor(int row, int /*column*/)
{
TagInfo::sptr info = Bookmarks::Get().findOrAddTag(item(row, 1)->text());
Expand All @@ -113,7 +117,8 @@ void BookmarksTagList::changeColor(int row, int /*column*/)
return;

info->color=color;
updateTags();
item(row,0)->setBackground(color);
emit colorChanged();
Bookmarks::Get().save();
}

Expand Down Expand Up @@ -225,7 +230,6 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos)
popupMenu->popup(viewport()->mapToGlobal(pos));
}

#if 0
bool BookmarksTagList::RenameSelectedTag()
{
QModelIndexList selected = selectionModel()->selectedRows();
Expand All @@ -236,19 +240,24 @@ bool BookmarksTagList::RenameSelectedTag()
}

int iRow = selected.first().row();
QTableWidgetItem* pItem = item(iRow,1);bUpdating
QTableWidgetItem* pItem = item(iRow,1);
editItem(pItem);
//Bookmarks::Get().save();

return true;
}
#endif

void BookmarksTagList::AddNewTag()
{
AddTag("*new*");
scrollToBottom();
editItem(item(rowCount()-1, 1));
constexpr const char * newItemName = "*new*";
QList<QTableWidgetItem *> found = findItems(newItemName, Qt::MatchExactly);
if(found.isEmpty())
{
m_bUpdating = true;
AddTag(newItemName);
scrollToBottom();
m_bUpdating = false;
editItem(item(rowCount()-1, 1));
}else
editItem(found[0]);
}

void BookmarksTagList::AddTag(QString name, Qt::CheckState checkstate, QColor color)
Expand All @@ -258,6 +267,7 @@ void BookmarksTagList::AddTag(QString name, Qt::CheckState checkstate, QColor co

// Column 1
QTableWidgetItem *item = new QTableWidgetItem(name);
item->setData(Qt::UserRole, name);
item->setCheckState(checkstate);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
setItem(i, 1, item);
Expand Down
4 changes: 3 additions & 1 deletion src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ class BookmarksTagList : public QTableWidget
bool m_bShowUntagged;
QMenu* popupMenu{nullptr};
signals:
void colorChanged();

public slots:
void updateTags();
void on_cellClicked(int row, int column);
void on_cellDoubleClicked(int row, int column);
void changeColor(int row, int column);
void toggleCheckedState(int row, int column);
void ShowContextMenu(const QPoint& pos);
//bool RenameSelectedTag();
bool RenameSelectedTag();
void AddNewTag();
void AddTag(QString name, Qt::CheckState checkstate = Qt::Checked, QColor color = TagInfo::DefaultColor);
void DeleteSelectedTag();
Expand Down
51 changes: 49 additions & 2 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), tagsDialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), tagsDialog, SLOT(reject()));
connect(dialogTaglist, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(dialog_tableWidgetTagList_itemChanged(QTableWidgetItem *)));
connect(dialogTaglist, SIGNAL(colorChanged()), this, SLOT(dialog_tableWidgetTagList_colorChanged()));

QVBoxLayout *mainLayout = new QVBoxLayout(tagsDialog);
mainLayout->addWidget(dialogTaglist);
Expand All @@ -103,7 +105,7 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
connect(bookmarksTableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(onDataChanged(const QModelIndex &, const QModelIndex &)));
connect(&Bookmarks::Get(), SIGNAL(TagListChanged()),
ui->tableWidgetTagList, SLOT(updateTags()));
ui->tableWidgetTagList, SLOT(updateTags()), Qt::QueuedConnection);
connect(&Bookmarks::Get(), SIGNAL(BookmarksChanged()),
bookmarksTableModel, SLOT(update()));
}
Expand Down Expand Up @@ -161,12 +163,57 @@ void DockBookmarks::on_tableWidgetTagList_itemChanged(QTableWidgetItem *item)
// we only want to react on changed by the user, not changes by the program itself.
if(ui->tableWidgetTagList->m_bUpdating) return;

int col = item->column();
if (col != 1)
return;

QString strText = item->text().trimmed();
QString strOld = item->data(Qt::UserRole).toString();
bool isChecked = (item->checkState() == Qt::Checked);
if(strText != strOld)
{
if((Bookmarks::Get().getTagIndex(strText) == -1)
&& (strText.compare(TagInfo::strUntagged) != 0)
&& (strOld.compare(TagInfo::strUntagged) != 0)
)
{
Bookmarks::Get().findOrAddTag(strOld)->name = strText;
Bookmarks::Get().save();
}
}
Bookmarks::Get().setTagChecked(strText, isChecked);
}

void DockBookmarks::dialog_tableWidgetTagList_itemChanged(QTableWidgetItem *item)
{
// we only want to react on changed by the user, not changes by the program itself.
if(ui->tableWidgetTagList->m_bUpdating) return;

int col = item->column();
if (col != 1)
return;

QString strText = item->text();
Bookmarks::Get().setTagChecked(strText, (item->checkState() == Qt::Checked));
QString strOld = item->data(Qt::UserRole).toString();
if(strText != strOld)
{
if((Bookmarks::Get().getTagIndex(strText) == -1)
&& (strText.compare(TagInfo::strUntagged) != 0)
&& (strOld.compare(TagInfo::strUntagged) != 0)
)
{
Bookmarks::Get().findOrAddTag(strOld)->name = strText;
item->setData(Qt::UserRole, strText);
Bookmarks::Get().save();
}else
item->setText(strOld);
updateTags();
}
}

void DockBookmarks::dialog_tableWidgetTagList_colorChanged()
{
updateTags();
}

bool DockBookmarks::eventFilter(QObject* object, QEvent* event)
Expand Down
2 changes: 2 additions & 0 deletions src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class DockBookmarks : public QDockWidget

public slots:
void setNewFrequency(qint64 rx_freq);
void dialog_tableWidgetTagList_itemChanged(QTableWidgetItem *item);
void dialog_tableWidgetTagList_colorChanged();

private slots:
void activated(const QModelIndex & index );
Expand Down

0 comments on commit 34d5cb0

Please sign in to comment.