From c942185947c688eff9fa68eaac27e40898f51b6d Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 30 Jul 2020 12:23:01 +0300 Subject: [PATCH] allow to copy all line measurements at once (fix #20498) --- src/app/qgsmeasuredialog.cpp | 20 ++++++++++++++++++++ src/app/qgsmeasuredialog.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/app/qgsmeasuredialog.cpp b/src/app/qgsmeasuredialog.cpp index 943887673d2..028b734cf82 100644 --- a/src/app/qgsmeasuredialog.cpp +++ b/src/app/qgsmeasuredialog.cpp @@ -27,6 +27,7 @@ #include "qgssettings.h" #include "qgsgui.h" +#include #include #include #include @@ -55,6 +56,13 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool *tool, Qt::WindowFlags f ) buttonBox->addButton( cb, QDialogButtonBox::ActionRole ); connect( cb, &QAbstractButton::clicked, this, &QgsMeasureDialog::openConfigTab ); + if ( !mMeasureArea ) + { + QPushButton *cpb = new QPushButton( tr( "Copy &All" ) ); + buttonBox->addButton( cpb, QDialogButtonBox::ActionRole ); + connect( cpb, &QAbstractButton::clicked, this, &QgsMeasureDialog::copyMeasurements ); + } + repopulateComboBoxUnits( mMeasureArea ); if ( mMeasureArea ) { @@ -646,6 +654,18 @@ double QgsMeasureDialog::convertArea( double area, QgsUnitTypes::AreaUnit toUnit return mDa.convertAreaMeasurement( area, toUnit ); } +void QgsMeasureDialog::copyMeasurements() +{ + QClipboard *clipboard = QApplication::clipboard(); + QString text; + QTreeWidgetItemIterator it( mTable ); + while ( *it ) + { + text += ( *it )->text( 0 ) + QStringLiteral( "\n" ); + it++; + } + clipboard->setText( text ); +} void QgsMeasureDialog::reject() { diff --git a/src/app/qgsmeasuredialog.h b/src/app/qgsmeasuredialog.h index 237387f1cfa..bd54aa1b721 100644 --- a/src/app/qgsmeasuredialog.h +++ b/src/app/qgsmeasuredialog.h @@ -70,6 +70,9 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase //! Open configuration tab void openConfigTab(); + //! Copy measurements to the clipboard + void copyMeasurements(); + void crsChanged(); void projChanged();