Skip to content
Permalink
Browse files

[FEATURE] add copy cell content action in attributetable context menu

  • Loading branch information
pblottiere authored and nyalldawson committed May 27, 2016
1 parent e0c87ff commit 3da3cf18b536c0949f771e41eb5f26c2ce6dca72
@@ -189,6 +189,12 @@ class QgsDualView : QStackedWidget
*/
void toggleSearchMode( bool enabled );

/**
* Copy the content of the selected cell in the clipboard.
* @note added in QGIS 1.16
*/
void copyCellContent() const;

signals:
/**
* Is emitted, whenever the display expression is successfully changed
@@ -26,6 +26,7 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayercache.h"

#include <QClipboard>
#include <QDialog>
#include <QMenu>
#include <QMessageBox>
@@ -379,13 +380,32 @@ int QgsDualView::filteredFeatureCount()
return mFilterModel->rowCount();
}

void QgsDualView::copyCellContent() const
{
QAction* action = qobject_cast<QAction*>( sender() );

if ( action && action->data().isValid() && action->data().canConvert<QModelIndex>() )
{
QModelIndex index = action->data().value<QModelIndex>();

QgsFeature f = masterModel()->feature( index );
QVariant var = f.attributes().at( index.column() );
QApplication::clipboard()->setText( var.toString() );
}
}

void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex )
{
if ( !menu )
{
return;
}

QAction *copyContentAction = new QAction( tr( "Copy cell content" ), this );
copyContentAction->setData( QVariant::fromValue<QModelIndex>( atIndex ) );
menu->addAction( copyContentAction );
connect( copyContentAction, SIGNAL( triggered() ), this, SLOT( copyCellContent() ) );

QgsVectorLayer* vl = mFilterModel->layer();
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
if ( canvas && vl && vl->geometryType() != QGis::NoGeometry )
@@ -226,6 +226,12 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
*/
void toggleSearchMode( bool enabled );

/**
* Copy the content of the selected cell in the clipboard.
* @note added in QGIS 1.16
*/
void copyCellContent() const;

signals:
/**
* Is emitted, whenever the display expression is successfully changed
@@ -358,4 +364,6 @@ class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
QModelIndex mFieldIdx;
};

Q_DECLARE_METATYPE( QModelIndex );

#endif // QGSDUALVIEW_H

0 comments on commit 3da3cf1

Please sign in to comment.
You can’t perform that action at this time.