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

Tags fixes #1398

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
105 changes: 52 additions & 53 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,42 @@ BookmarksTagList::BookmarksTagList(QWidget *parent, bool bShowUntagged )
this, SLOT(on_cellClicked(int,int)));

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

// MenuItem "Rename"
{
QAction* actionRename = new QAction("Rename", this);
popupMenu->addAction(actionRename);
connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag()));
}

// MenuItem "Create new Tag"
{
QAction* actionNewTag = new QAction("Create new Tag", this);
popupMenu->addAction(actionNewTag);
connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag()));
}

// Menu "Delete Tag"
{
QAction* actionDeleteTag = new QAction("Delete Tag", this);
popupMenu->addAction(actionDeleteTag);
connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag()));
}

// Menu "Select All"
{
QAction* action = new QAction("Select All", this);
popupMenu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(SelectAll()));
}

// Menu "Deselect All"
{
QAction* action = new QAction("Deselect All", this);
popupMenu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(DeselectAll()));
}
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(ShowContextMenu(const QPoint&)));
Expand Down Expand Up @@ -71,7 +107,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 @@ -180,53 +217,9 @@ QStringList BookmarksTagList::getSelectedTags()

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"
{
QAction* actionNewTag = new QAction("Create new Tag", this);
menu->addAction(actionNewTag);
connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag()));
}

// Menu "Delete Tag"
{
QAction* actionDeleteTag = new QAction("Delete Tag", this);
menu->addAction(actionDeleteTag);
connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag()));
}

// Menu "Select All"
{
QAction* action = new QAction("Select All", this);
menu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(SelectAll()));
}

// Menu "Deselect All"
{
QAction* action = new QAction("Deselect All", this);
menu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(DeselectAll()));
}

menu->popup(viewport()->mapToGlobal(pos));
popupMenu->popup(viewport()->mapToGlobal(pos));
}

#if 0
bool BookmarksTagList::RenameSelectedTag()
{
QModelIndexList selected = selectionModel()->selectedRows();
Expand All @@ -237,19 +230,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 @@ -259,6 +257,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
5 changes: 3 additions & 2 deletions src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ class BookmarksTagList : public QTableWidget

private:
bool m_bShowUntagged;

QMenu* popupMenu{nullptr};
signals:
void colorChanged();

public slots:
void updateTags();
void on_cellClicked(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
88 changes: 67 additions & 21 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <QMessageBox>

#include "bookmarks.h"
#include "bookmarkstaglist.h"
#include "dockbookmarks.h"
#include "dockrxopt.h"
#include "qtcolorpicker.h"
Expand Down Expand Up @@ -73,6 +72,22 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
connect(ui->tableViewFrequencyList, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(ShowContextMenu(const QPoint&)));

tagsDialog = new QDialog(this);
tagsDialog->setWindowTitle("Change Bookmark Tags");

dialogTaglist = new BookmarksTagList(tagsDialog, false);

QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| 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);
mainLayout->addWidget(buttonBox);

// Update GUI
Bookmarks::Get().load();
bookmarksTableModel->update();
Expand Down Expand Up @@ -148,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 Expand Up @@ -249,27 +309,13 @@ void DockBookmarks::changeBookmarkTags(int row, int /*column*/)
// Create and show the Dialog for a new Bookmark.
// Write the result into variable 'tags'.
{
QDialog dialog(this);
dialog.setWindowTitle("Change Bookmark Tags");

BookmarksTagList* taglist = new BookmarksTagList(&dialog, false);
taglist->updateTags();
taglist->setSelectedTags(bmi.tags);
taglist->DeleteTag(TagInfo::strUntagged);

QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));

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

ok = dialog.exec();
dialogTaglist->updateTags();
dialogTaglist->setSelectedTags(bmi.tags);
dialogTaglist->DeleteTag(TagInfo::strUntagged);
ok = tagsDialog->exec();
if (ok)
{
tags = taglist->getSelectedTags();
tags = dialogTaglist->getSelectedTags();

// Change Tags of Bookmark
bmi.tags.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDockWidget>
#include <QTableWidgetItem>
#include "qtgui/bookmarkstablemodel.h"
#include "qtgui/bookmarkstaglist.h"
#include <QItemDelegate>

namespace Ui {
Expand All @@ -48,6 +49,8 @@ class DockBookmarks : public QDockWidget
private:
Ui::DockBookmarks *ui;
QMenu* contextmenu;
QDialog* tagsDialog;
BookmarksTagList* dialogTaglist;
qint64 m_currentFrequency;
bool m_updating;
BookmarksTableModel *bookmarksTableModel;
Expand Down Expand Up @@ -78,6 +81,8 @@ private slots:
//void on_addButton_clicked();
//void on_delButton_clicked();
void on_tableWidgetTagList_itemChanged(QTableWidgetItem* item);
void dialog_tableWidgetTagList_itemChanged(QTableWidgetItem *item);
void dialog_tableWidgetTagList_colorChanged();
void ShowContextMenu(const QPoint&pos);
bool DeleteSelectedBookmark();
void doubleClicked(const QModelIndex & index);
Expand Down
Loading