diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-03 12:51:54 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-03 12:51:54 +0100 |
| commit | 3366d9f192ef88cccc2d901c666e15061db20b4e (patch) | |
| tree | d65ce6bfdcd6ddbc4ce48df453613057eca18b1e /src/copyeventfilter.h | |
| parent | c36d1126df94d879181a95d63862117a62d5ff60 (diff) | |
Create CopyEventFilter. Add Ctrl+C to the plugin list.
Diffstat (limited to 'src/copyeventfilter.h')
| -rw-r--r-- | src/copyeventfilter.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/copyeventfilter.h b/src/copyeventfilter.h new file mode 100644 index 00000000..1243630b --- /dev/null +++ b/src/copyeventfilter.h @@ -0,0 +1,43 @@ +#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 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 + // + bool copySelection() const; + + bool eventFilter(QObject* sender, QEvent* event) override; + +private: + + QAbstractItemView* m_view; + std::function<QString(const QModelIndex&)> m_format; + +}; + +#endif |
