Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FEATURE] add copy cell content action in attributetable context menu
- Loading branch information
|
@@ -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 |