Permalink
Browse files

Copy plot to clipboard

New context menu and shortcut (context restricted to widget) for copying
the current plot to the clipboard as a pixmap.
  • Loading branch information...
mgrojo committed Dec 12, 2017
1 parent d2200de commit e34d36085df827999935ab0c94cf44ef2bd08736
Showing with 31 additions and 0 deletions.
  1. +27 −0 src/PlotDock.cpp
  2. +4 −0 src/PlotDock.h
@@ -28,6 +28,28 @@ PlotDock::PlotDock(QWidget* parent)
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotWidget, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotWidget, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

QShortcut* shortcutCopy = new QShortcut(QKeySequence::Copy, ui->plotWidget, nullptr, nullptr, Qt::WidgetShortcut);
connect(shortcutCopy, SIGNAL(activated()), this, SLOT(copy()));

ui->plotWidget->setContextMenuPolicy(Qt::CustomContextMenu);

// Set up context menu
m_contextMenu = new QMenu(this);
QAction* copyAction = new QAction(QIcon(":/icons/copy"), tr("Copy"), m_contextMenu);
copyAction->setShortcut(shortcutCopy->key());
m_contextMenu->addAction(copyAction);

connect(copyAction, &QAction::triggered, [&]() {
copy();
});

connect(ui->plotWidget, &QTableView::customContextMenuRequested,
[=](const QPoint& pos) {
// Show menu
m_contextMenu->popup(ui->plotWidget->mapToGlobal(pos));
});

}

PlotDock::~PlotDock()
@@ -612,3 +634,8 @@ void PlotDock::mouseWheel()
else
ui->plotWidget->axisRect()->setRangeZoom(Qt::Horizontal | Qt::Vertical);
}

void PlotDock::copy()
{
QApplication::clipboard()->setPixmap(ui->plotWidget->toPixmap());
}
@@ -3,6 +3,7 @@

#include <QDialog>
#include <QVariant>
#include <QMenu>

class SqliteTableModel;
class QTreeWidgetItem;
@@ -81,6 +82,7 @@ public slots:

SqliteTableModel* m_currentPlotModel;
BrowseDataTableSettings* m_currentTableSettings;
QMenu* m_contextMenu;

/*!
* \brief guessdatatype try to parse the first 10 rows and decide the datatype
@@ -99,6 +101,8 @@ private slots:
void selectionChanged();
void mousePress();
void mouseWheel();
void copy();

};

#endif

0 comments on commit e34d360

Please sign in to comment.