Skip to content

Commit f16ee3e

Browse files
committedMay 19, 2020
use value from context when copying variables from the editor widget
(fix #30641)
1 parent 8499e09 commit f16ee3e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
 

‎src/gui/qgsvariableeditorwidget.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <QPushButton>
2929
#include <QHeaderView>
3030
#include <QMessageBox>
31-
31+
#include <QClipboard>
3232

3333
//
3434
// QgsVariableEditorWidget
@@ -627,6 +627,25 @@ void QgsVariableEditorTree::keyPressEvent( QKeyEvent *event )
627627
default:
628628
break;
629629
}
630+
631+
if ( event == QKeySequence::Copy )
632+
{
633+
QList<QTreeWidgetItem *> selected = selectedItems();
634+
if ( selected.size() > 0 )
635+
{
636+
QString text = selected.at( 0 )->text( 0 );
637+
QString varName = variableNameFromItem( selected.at( 0 ) );
638+
QgsExpressionContextScope *scope = scopeFromItem( selected.at( 0 ) );
639+
if ( !varName.isEmpty() && scope )
640+
text = scope->variable( varName ).toString();
641+
642+
QClipboard *clipboard = QApplication::clipboard();
643+
clipboard->setText( text );
644+
event->accept();
645+
return;
646+
}
647+
}
648+
630649
QTreeWidget::keyPressEvent( event );
631650
}
632651

0 commit comments

Comments
 (0)
Please sign in to comment.