Allow to copy selected DB query result
This commit is contained in:
parent
1e6facc2a8
commit
6b97860771
|
@ -23,6 +23,9 @@
|
|||
#include <QMenu>
|
||||
#include <QStyle>
|
||||
#include <QTextBrowser>
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
#include <QClipboard>
|
||||
#endif
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
@ -456,6 +459,9 @@ void DbQueryWidget::showResultsContextMenu()
|
|||
static_cast<void (DbQueryWidget::*)(void)>(&DbQueryWidget::applySelectedResults));
|
||||
}
|
||||
if (m_model && m_model->areResultsAvailable()) {
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy value"), this, &DbQueryWidget::copySelectedResult);
|
||||
#endif
|
||||
if (!contextMenu.isEmpty()) {
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
|
@ -466,9 +472,32 @@ void DbQueryWidget::showResultsContextMenu()
|
|||
contextMenu.addAction(
|
||||
QIcon::fromTheme(QStringLiteral("internet-web-browser")), tr("Show in browser"), this, &DbQueryWidget::openSelectionInBrowser);
|
||||
}
|
||||
contextMenu.exec(QCursor::pos());
|
||||
m_contextMenuPos = QCursor::pos();
|
||||
contextMenu.exec(m_contextMenuPos);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
void DbQueryWidget::copySelectedResult()
|
||||
{
|
||||
auto *const clipboard = QGuiApplication::clipboard();
|
||||
if (!clipboard) {
|
||||
return;
|
||||
}
|
||||
const auto selectedIndex = this->selectedIndex();
|
||||
if (!selectedIndex.isValid()) {
|
||||
return;
|
||||
}
|
||||
const auto clickedColumnIndex = m_ui->resultsTreeView->indexAt(m_ui->resultsTreeView->mapFromGlobal(m_contextMenuPos));
|
||||
if (!clickedColumnIndex.isValid()) {
|
||||
return;
|
||||
}
|
||||
const auto value = m_model->data(m_model->index(selectedIndex.row(), clickedColumnIndex.column()));
|
||||
if (value.isValid()) {
|
||||
clipboard->setText(value.toString());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void DbQueryWidget::fetchAndShowCoverForSelection()
|
||||
{
|
||||
const auto selectedIndex = this->selectedIndex();
|
||||
|
|
|
@ -51,6 +51,9 @@ private slots:
|
|||
void setStatus(bool aborted);
|
||||
void fileStatusChanged(bool opened, bool hasTags);
|
||||
void showResultsContextMenu();
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
void copySelectedResult();
|
||||
#endif
|
||||
void fetchAndShowCoverForSelection();
|
||||
void fetchAndShowLyricsForSelection();
|
||||
void openSelectionInBrowser();
|
||||
|
@ -72,6 +75,7 @@ private:
|
|||
int m_coverIndex, m_lyricsIndex;
|
||||
QMenu *m_menu;
|
||||
QAction *m_insertPresentDataAction;
|
||||
QPoint m_contextMenuPos;
|
||||
};
|
||||
|
||||
} // namespace QtGui
|
||||
|
|
Loading…
Reference in New Issue