blob: 0ad515844f470abe18843af18e8eaa260aa6ef0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#ifndef COPY_EVENT_FILTER_H
#define COPY_EVENT_FILTER_H
#include <functional>
#include <QAbstractItemView>
#include <QModelIndex>
#include <QObject>
// this small class provides copy on Ctrl+C and also
// exposes a method to actual copy the selection
//
// the way the selection is copied can be customized by
// passing a functor to format each index, by default
// it only extracts the display role
//
// only works for view that selects whole row since it only
// considers the first cell in each row
//
class CopyEventFilter : public QObject
{
Q_OBJECT
public:
CopyEventFilter(QAbstractItemView* view, int column = 0, int role = Qt::DisplayRole);
CopyEventFilter(QAbstractItemView* view,
std::function<QString(const QModelIndex&)> format);
// copy the selection of the view associated with this
// event filter into the clipboard
//
void copySelection() const;
bool eventFilter(QObject* sender, QEvent* event) override;
private:
QAbstractItemView* m_view;
std::function<QString(const QModelIndex&)> m_format;
};
#endif
|