mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[FEATURE] add copy cell content action in attributetable context menu
This commit is contained in:
parent
e0c87ffe6b
commit
3da3cf18b5
@ -189,6 +189,12 @@ class QgsDualView : QStackedWidget
|
|||||||
*/
|
*/
|
||||||
void toggleSearchMode( bool enabled );
|
void toggleSearchMode( bool enabled );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the content of the selected cell in the clipboard.
|
||||||
|
* @note added in QGIS 1.16
|
||||||
|
*/
|
||||||
|
void copyCellContent() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* Is emitted, whenever the display expression is successfully changed
|
* Is emitted, whenever the display expression is successfully changed
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "qgsvectordataprovider.h"
|
#include "qgsvectordataprovider.h"
|
||||||
#include "qgsvectorlayercache.h"
|
#include "qgsvectorlayercache.h"
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -379,6 +380,20 @@ int QgsDualView::filteredFeatureCount()
|
|||||||
return mFilterModel->rowCount();
|
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 )
|
void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex )
|
||||||
{
|
{
|
||||||
if ( !menu )
|
if ( !menu )
|
||||||
@ -386,6 +401,11 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
|
|||||||
return;
|
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();
|
QgsVectorLayer* vl = mFilterModel->layer();
|
||||||
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
|
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
|
||||||
if ( canvas && vl && vl->geometryType() != QGis::NoGeometry )
|
if ( canvas && vl && vl->geometryType() != QGis::NoGeometry )
|
||||||
|
@ -226,6 +226,12 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
|
|||||||
*/
|
*/
|
||||||
void toggleSearchMode( bool enabled );
|
void toggleSearchMode( bool enabled );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the content of the selected cell in the clipboard.
|
||||||
|
* @note added in QGIS 1.16
|
||||||
|
*/
|
||||||
|
void copyCellContent() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* Is emitted, whenever the display expression is successfully changed
|
* Is emitted, whenever the display expression is successfully changed
|
||||||
@ -358,4 +364,6 @@ class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
|
|||||||
QModelIndex mFieldIdx;
|
QModelIndex mFieldIdx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QModelIndex );
|
||||||
|
|
||||||
#endif // QGSDUALVIEW_H
|
#endif // QGSDUALVIEW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user