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

Implement tag renaming #1165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,8 @@ void MainWindow::on_actionAddBookmark_triggered()
connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
connect(buttonCreateTag, SIGNAL(clicked()), taglist, SLOT(AddNewTag()));
connect(&Bookmarks::Get(), SIGNAL(TagListChanged()),
taglist, SLOT(updateTags()));

auto *mainLayout = new QVBoxLayout(&dialog);
mainLayout->addWidget(LabelAndTextfieldName);
Expand Down
26 changes: 26 additions & 0 deletions src/qtgui/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ bool Bookmarks::removeTag(QString tagName)
return true;
}

bool Bookmarks::renameTag(QString oldName, QString newName)
{
oldName = oldName.trimmed();
newName = newName.trimmed();

if(oldName == TagInfo::strUntagged || oldName == "")
return false;

if (oldName == newName)
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 300..310 can be removed. I missed the same check at the line 254.
Or it may be better to remove check on line 254 as it looks better to compare trimmed strings.


if (getTagIndex(newName) != -1)
return false;

const int idx = getTagIndex(oldName);
if (idx == -1)
return false;

m_TagList[idx].name = newName;

emit BookmarksChanged();
emit TagListChanged();

return true;
}

bool Bookmarks::setTagChecked(QString tagName, bool bChecked)
{
int idx = getTagIndex(tagName);
Expand Down
1 change: 1 addition & 0 deletions src/qtgui/bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Bookmarks : public QObject
TagInfo& findOrAddTag(QString tagName);
int getTagIndex(QString tagName);
bool removeTag(QString tagName);
bool renameTag(QString oldName, QString newName);
bool setTagChecked(QString tagName, bool bChecked);

void setConfigDir(const QString&);
Expand Down
29 changes: 19 additions & 10 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ BookmarksTagList::BookmarksTagList(QWidget *parent, bool bShowUntagged )
connect(this, SIGNAL(cellClicked(int,int)),
this, SLOT(on_cellClicked(int,int)));

connect(this, SIGNAL(itemChanged(QTableWidgetItem *)),
this, SLOT(on_itemChanged(QTableWidgetItem *)));

// right click menu
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
Expand Down Expand Up @@ -182,18 +185,12 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos)
{
QMenu* menu=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);
menu->addAction(actionRename);
connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag()));
}
#endif

// MenuItem "Create new Tag"
{
Expand Down Expand Up @@ -226,7 +223,6 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos)
menu->popup(viewport()->mapToGlobal(pos));
}

#if 0
bool BookmarksTagList::RenameSelectedTag()
{
QModelIndexList selected = selectionModel()->selectedRows();
Expand All @@ -237,13 +233,11 @@ 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()
{
Expand All @@ -252,13 +246,28 @@ void BookmarksTagList::AddNewTag()
editItem(item(rowCount()-1, 1));
}

void BookmarksTagList::on_itemChanged(QTableWidgetItem *item) {
if (m_bUpdating)
return;

QString id = item->data(Qt::UserRole).toString();
if (id == item->text())
return;

item->setData(Qt::UserRole, item->text());

Bookmarks::Get().renameTag(id, item->text());
Bookmarks::Get().save();
}

void BookmarksTagList::AddTag(QString name, Qt::CheckState checkstate, QColor color)
{
int i = rowCount();
setRowCount(i+1);

// Column 1
QTableWidgetItem *item = new QTableWidgetItem(name);
item->setData(Qt::UserRole, QVariant(name));
item->setCheckState(checkstate);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
setItem(i, 1, item);
Expand Down
5 changes: 4 additions & 1 deletion src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class BookmarksTagList : public QTableWidget
private:
bool m_bShowUntagged;

private slots:
void on_itemChanged(QTableWidgetItem *item);

signals:

public slots:
Expand All @@ -48,7 +51,7 @@ public slots:
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
2 changes: 2 additions & 0 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ void DockBookmarks::changeBookmarkTags(int row, int /*column*/)
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
connect(&Bookmarks::Get(), SIGNAL(TagListChanged()),
taglist, SLOT(updateTags()));

QVBoxLayout *mainLayout = new QVBoxLayout(&dialog);
mainLayout->addWidget(taglist);
Expand Down