Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 e34d360
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/PlotDock.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}
4 changes: 4 additions & 0 deletions src/PlotDock.h
Expand Up @@ -3,6 +3,7 @@

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

class SqliteTableModel;
class QTreeWidgetItem;
Expand Down Expand Up @@ -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
Expand All @@ -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.