Skip to content

Commit

Permalink
Copy plot to clipboard
Browse files Browse the repository at this point in the history
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
Original file line number Original file line Diff line number Diff line change
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 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(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotWidget, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel())); 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() PlotDock::~PlotDock()
Expand Down Expand Up @@ -612,3 +634,8 @@ void PlotDock::mouseWheel()
else else
ui->plotWidget->axisRect()->setRangeZoom(Qt::Horizontal | Qt::Vertical); 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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


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


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


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


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

}; };


#endif #endif

0 comments on commit e34d360

Please sign in to comment.