diff --git a/src/qtgui/bookmarkstablemodel.cpp b/src/qtgui/bookmarkstablemodel.cpp index 4fc5cc239..e111c6476 100644 --- a/src/qtgui/bookmarkstablemodel.cpp +++ b/src/qtgui/bookmarkstablemodel.cpp @@ -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; } @@ -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]; } diff --git a/src/qtgui/bookmarkstablemodel.h b/src/qtgui/bookmarkstablemodel.h index f8b2e6274..0b4c7dde9 100644 --- a/src/qtgui/bookmarkstablemodel.h +++ b/src/qtgui/bookmarkstablemodel.h @@ -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 m_Bookmarks; diff --git a/src/qtgui/dockbookmarks.cpp b/src/qtgui/dockbookmarks.cpp index ff518588d..a06eb5e49 100644 --- a/src/qtgui/dockbookmarks.cpp +++ b/src/qtgui/dockbookmarks.cpp @@ -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 @@ -77,7 +82,6 @@ DockBookmarks::DockBookmarks(QWidget *parent) : Bookmarks::Get().load(); bookmarksTableModel->update(); - m_currentFrequency = 0; m_updating = false; // TagList @@ -85,8 +89,6 @@ DockBookmarks::DockBookmarks(QWidget *parent) : 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()), @@ -121,7 +123,6 @@ void DockBookmarks::setNewFrequency(qint64 rx_freq) break; } } - m_currentFrequency = rx_freq; } void DockBookmarks::updateTags() @@ -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 &) { @@ -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. @@ -174,7 +175,7 @@ bool DockBookmarks::eventFilter(QObject* object, QEvent* event) } } } - return QWidget::eventFilter(object, event); + return false; } bool DockBookmarks::DeleteSelectedBookmark() @@ -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) { @@ -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(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(editor); + if (!dlg || dlg->result() != QDialog::Accepted) + { + return; + } + BookmarksTagList *taglist = editor->findChild(); + if (!taglist) + { + return; + } + auto selectedTags = taglist->getSelectedTags(); + auto *mod = qobject_cast(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(); } diff --git a/src/qtgui/dockbookmarks.h b/src/qtgui/dockbookmarks.h index baf3818b0..c7d3cd28b 100644 --- a/src/qtgui/dockbookmarks.h +++ b/src/qtgui/dockbookmarks.h @@ -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 @@ -48,7 +58,6 @@ class DockBookmarks : public QDockWidget private: Ui::DockBookmarks *ui; QMenu* contextmenu; - qint64 m_currentFrequency; bool m_updating; BookmarksTableModel *bookmarksTableModel; @@ -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); @@ -80,5 +87,4 @@ private slots: void on_tableWidgetTagList_itemChanged(QTableWidgetItem* item); void ShowContextMenu(const QPoint&pos); bool DeleteSelectedBookmark(); - void doubleClicked(const QModelIndex & index); };