Skip to content

Commit

Permalink
bookmarks: Support tag renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Nov 10, 2024
1 parent 93aa0ab commit 684b145
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,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 +220,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 +230,10 @@ 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 @@ -259,6 +249,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
2 changes: 1 addition & 1 deletion src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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
12 changes: 11 additions & 1 deletion src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ void DockBookmarks::on_tableWidgetTagList_itemChanged(QTableWidgetItem *item)
return;

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

bool DockBookmarks::eventFilter(QObject* object, QEvent* event)
Expand Down

0 comments on commit 684b145

Please sign in to comment.