Skip to content

Commit

Permalink
Implement tag renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jiri-pinkava committed Nov 9, 2022
1 parent 23c6ad1 commit 3244ae3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
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;

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
30 changes: 20 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,29 @@ 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());
qWarning() << __func__ << 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

0 comments on commit 3244ae3

Please sign in to comment.