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

Consistent bookmark tags edition with single click #1308

Open
wants to merge 6 commits 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
9 changes: 3 additions & 6 deletions src/qtgui/bookmarkstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@ Qt::ItemFlags BookmarksTableModel::flags ( const QModelIndex& index ) const
case COL_NAME:
case COL_BANDWIDTH:
case COL_MODULATION:
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
break;
case COL_TAGS:
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
break;
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
return flags;
}
Expand Down Expand Up @@ -214,12 +211,12 @@ void BookmarksTableModel::update()
emit layoutChanged();
}

BookmarkInfo *BookmarksTableModel::getBookmarkAtRow(int row)
BookmarkInfo *BookmarksTableModel::getBookmarkAtRow(int row) const
{
return m_Bookmarks[row];
}

int BookmarksTableModel::GetBookmarksIndexForRow(int iRow)
int BookmarksTableModel::GetBookmarksIndexForRow(int iRow) const
{
return m_mapRowToBookmarksIndex[iRow];
}
4 changes: 2 additions & 2 deletions src/qtgui/bookmarkstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class BookmarksTableModel : public QAbstractTableModel
bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
Qt::ItemFlags flags ( const QModelIndex & index ) const;

BookmarkInfo* getBookmarkAtRow(int row);
int GetBookmarksIndexForRow(int iRow);
BookmarkInfo* getBookmarkAtRow(int row) const;
int GetBookmarksIndexForRow(int iRow) const;

private:
QList<BookmarkInfo*> m_Bookmarks;
Expand Down
126 changes: 72 additions & 54 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
ui->tableViewFrequencyList->columnWidth(BookmarksTableModel::COL_NAME) * 2);
ui->tableViewFrequencyList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableViewFrequencyList->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableViewFrequencyList->setEditTriggers(QAbstractItemView::SelectedClicked);
ui->tableViewFrequencyList->installEventFilter(this);

// Demod Selection in Frequency List Table.
ComboBoxDelegateModulation* delegateModulation = new ComboBoxDelegateModulation(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(2, delegateModulation);

// Tag Selection in Frequency List Table.
DialogDelegateTags* delegateTag = new DialogDelegateTags(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(4, delegateTag);

// Bookmarks Context menu
contextmenu = new QMenu(this);
// MenuItem Delete
Expand All @@ -77,16 +82,13 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
Bookmarks::Get().load();
bookmarksTableModel->update();

m_currentFrequency = 0;
m_updating = false;

// TagList
updateTags();

connect(ui->tableViewFrequencyList, SIGNAL(activated(const QModelIndex &)),
this, SLOT(activated(const QModelIndex &)));
connect(ui->tableViewFrequencyList, SIGNAL(doubleClicked(const QModelIndex &)),
this, SLOT(doubleClicked(const QModelIndex &)));
connect(bookmarksTableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(onDataChanged(const QModelIndex &, const QModelIndex &)));
connect(&Bookmarks::Get(), SIGNAL(TagListChanged()),
Expand Down Expand Up @@ -121,7 +123,6 @@ void DockBookmarks::setNewFrequency(qint64 rx_freq)
break;
}
}
m_currentFrequency = rx_freq;
}

void DockBookmarks::updateTags()
Expand All @@ -131,11 +132,6 @@ void DockBookmarks::updateTags()
m_updating = false;
}

void DockBookmarks::updateBookmarks()
{
bookmarksTableModel->update();
}

//Data has been edited
void DockBookmarks::onDataChanged(const QModelIndex&, const QModelIndex &)
{
Expand All @@ -158,6 +154,11 @@ void DockBookmarks::on_tableWidgetTagList_itemChanged(QTableWidgetItem *item)

bool DockBookmarks::eventFilter(QObject* object, QEvent* event)
{
// Prevent field to go in editing if user clicks already selected bookmark
if (event->type() == QEvent::FocusIn)
{
ui->tableViewFrequencyList->clearSelection();
}
// Since Key_Delete can be (is) used as a global shortcut, override the
// shortcut. Accepting a ShortcutOverride causes the event to be delivered
// again, but as a KeyPress.
Expand All @@ -174,7 +175,7 @@ bool DockBookmarks::eventFilter(QObject* object, QEvent* event)
}
}
}
return QWidget::eventFilter(object, event);
return false;
}

bool DockBookmarks::DeleteSelectedBookmark()
Expand All @@ -200,14 +201,6 @@ void DockBookmarks::ShowContextMenu(const QPoint& pos)
contextmenu->popup(ui->tableViewFrequencyList->viewport()->mapToGlobal(pos));
}

void DockBookmarks::doubleClicked(const QModelIndex & index)
{
if(index.column() == BookmarksTableModel::COL_TAGS)
{
changeBookmarkTags(index.row(), index.column());
}
}

ComboBoxDelegateModulation::ComboBoxDelegateModulation(QObject *parent)
:QItemDelegate(parent)
{
Expand Down Expand Up @@ -238,50 +231,75 @@ void ComboBoxDelegateModulation::setModelData(QWidget *editor, QAbstractItemMode
model->setData(index, comboBox->currentText(), Qt::EditRole);
}

void DockBookmarks::changeBookmarkTags(int row, int /*column*/)
DialogDelegateTags::DialogDelegateTags(QObject *parent)
:QItemDelegate(parent)
{
}

QWidget * DialogDelegateTags::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
bool ok = false;
QStringList tags;
QDialog* tagSelect = new QDialog(parent, Qt::WindowTitleHint);

tagSelect->setWindowTitle("Change Bookmark Tags");

BookmarksTagList* taglist = new BookmarksTagList(tagSelect, false);

int iIdx = bookmarksTableModel->GetBookmarksIndexForRow(row);
BookmarkInfo& bmi = Bookmarks::Get().getBookmark(iIdx);
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
, tagSelect);
connect(buttonBox, SIGNAL(accepted()), tagSelect, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), tagSelect, SLOT(reject()));

// Create and show the Dialog for a new Bookmark.
// Write the result into variable 'tags'.
taglist->updateTags();
auto const* mod = qobject_cast<const BookmarksTableModel *>(index.model());
if (!mod)
{
QDialog dialog(this);
dialog.setWindowTitle("Change Bookmark Tags");
return nullptr;
}
auto *bmInfo = mod->getBookmarkAtRow(index.row());
taglist->setSelectedTags(bmInfo->tags);

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

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

QVBoxLayout *mainLayout = new QVBoxLayout(&dialog);
mainLayout->addWidget(taglist);
mainLayout->addWidget(buttonBox);
void DialogDelegateTags::setEditorData(QWidget *editor, const QModelIndex &index) const
{
editor->resize(editor->sizeHint());
}

ok = dialog.exec();
if (ok)
{
tags = taglist->getSelectedTags();
void DialogDelegateTags::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
auto *dlg = qobject_cast<QDialog *>(editor);
if (!dlg || dlg->result() != QDialog::Accepted)
{
return;
}
BookmarksTagList *taglist = editor->findChild<BookmarksTagList*>();
if (!taglist)
{
return;
}
auto selectedTags = taglist->getSelectedTags();
auto *mod = qobject_cast<BookmarksTableModel *>(model);
if (!mod)
{
return;
}
auto &bmTags = mod->getBookmarkAtRow(index.row())->tags;

// Change Tags of Bookmark
bmi.tags.clear();
if (tags.size() == 0)
{
bmi.tags.append(Bookmarks::Get().findOrAddTag("")); // "Untagged"
}
for (int i = 0; i < tags.size(); ++i)
{
bmi.tags.append(Bookmarks::Get().findOrAddTag(tags[i]));
}
Bookmarks::Get().save();
}
// Change Tags of Bookmark
bmTags.clear();
if (selectedTags.isEmpty())
{
bmTags.append(Bookmarks::Get().findOrAddTag("")); // "Untagged"
}
for (auto const &tag: selectedTags)
{
bmTags.append(Bookmarks::Get().findOrAddTag(tag));
}
Bookmarks::Get().save();
}
22 changes: 14 additions & 8 deletions src/qtgui/dockbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ class ComboBoxDelegateModulation : public QItemDelegate
{
Q_OBJECT
public:
ComboBoxDelegateModulation(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
ComboBoxDelegateModulation(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};

class DialogDelegateTags : public QItemDelegate
{
Q_OBJECT
public:
DialogDelegateTags(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};

class DockBookmarks : public QDockWidget
Expand All @@ -48,7 +58,6 @@ class DockBookmarks : public QDockWidget
private:
Ui::DockBookmarks *ui;
QMenu* contextmenu;
qint64 m_currentFrequency;
bool m_updating;
BookmarksTableModel *bookmarksTableModel;

Expand All @@ -63,8 +72,6 @@ class DockBookmarks : public QDockWidget
QAction* actionAddBookmark;

void updateTags();
void updateBookmarks();
void changeBookmarkTags(int row, int /*column*/);

signals:
void newBookmarkActivated(qint64, QString, int);
Expand All @@ -80,5 +87,4 @@ private slots:
void on_tableWidgetTagList_itemChanged(QTableWidgetItem* item);
void ShowContextMenu(const QPoint&pos);
bool DeleteSelectedBookmark();
void doubleClicked(const QModelIndex & index);
};