|
12 | 12 | * (at your option) any later version. *
|
13 | 13 | * *
|
14 | 14 | ***************************************************************************/
|
15 |
| -#include "qgsstatisticalsummarydockwidget.h" |
16 |
| -#include "qgsstatisticalsummary.h" |
17 |
| -#include "qgsproject.h" |
| 15 | + |
18 | 16 | #include "qgisapp.h"
|
| 17 | +#include "qgsclipboard.h" |
19 | 18 | #include "qgsmapcanvas.h"
|
20 |
| -#include "qgsvectorlayer.h" |
| 19 | +#include "qgsproject.h" |
21 | 20 | #include "qgssettings.h"
|
| 21 | +#include "qgsstatisticalsummarydockwidget.h" |
| 22 | +#include "qgsstatisticalsummary.h" |
| 23 | +#include "qgsvectorlayer.h" |
22 | 24 |
|
23 | 25 | #include <QTableWidget>
|
24 | 26 | #include <QAction>
|
@@ -93,6 +95,7 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
|
93 | 95 | connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsStatisticalSummaryDockWidget::layerChanged );
|
94 | 96 | connect( mFieldExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString & )>( &QgsFieldExpressionWidget::fieldChanged ), this, &QgsStatisticalSummaryDockWidget::fieldChanged );
|
95 | 97 | connect( mSelectedOnlyCheckBox, &QAbstractButton::toggled, this, &QgsStatisticalSummaryDockWidget::refreshStatistics );
|
| 98 | + connect( mButtonCopy, &QAbstractButton::clicked, this, &QgsStatisticalSummaryDockWidget::copyStatistics ); |
96 | 99 | connect( mButtonRefresh, &QAbstractButton::clicked, this, &QgsStatisticalSummaryDockWidget::refreshStatistics );
|
97 | 100 | connect( QgsProject::instance(), static_cast<void ( QgsProject::* )( const QStringList & )>( &QgsProject::layersWillBeRemoved ), this, &QgsStatisticalSummaryDockWidget::layersRemoved );
|
98 | 101 |
|
@@ -121,6 +124,34 @@ void QgsStatisticalSummaryDockWidget::fieldChanged()
|
121 | 124 | }
|
122 | 125 | }
|
123 | 126 |
|
| 127 | +void QgsStatisticalSummaryDockWidget::copyStatistics() |
| 128 | +{ |
| 129 | + QStringList rows; |
| 130 | + QStringList columns; |
| 131 | + for ( int i = 0; i < mStatisticsTable->rowCount(); i++ ) |
| 132 | + { |
| 133 | + for ( int j = 0; j < mStatisticsTable->columnCount(); j++ ) |
| 134 | + { |
| 135 | + QTableWidgetItem *item = mStatisticsTable->item( i, j ); |
| 136 | + columns += item->text(); |
| 137 | + } |
| 138 | + rows += columns.join( QStringLiteral( "\t" ) ); |
| 139 | + columns.clear(); |
| 140 | + } |
| 141 | + |
| 142 | + if ( !rows.isEmpty() ) |
| 143 | + { |
| 144 | + QString text = QString( "%1\t%2\n%3" ).arg( mStatisticsTable->horizontalHeaderItem( 0 )->text(), |
| 145 | + mStatisticsTable->horizontalHeaderItem( 1 )->text(), |
| 146 | + rows.join( QStringLiteral( "\n" ) ) ); |
| 147 | + QString html = QString( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/></head><body><table border=\"1\"><tr><td>%1</td></tr></table></body></html>" ).arg( text ); |
| 148 | + html.replace( QStringLiteral( "\t" ), QStringLiteral( "</td><td>" ) ).replace( QStringLiteral( "\n" ), QStringLiteral( "</td></tr><tr><td>" ) ); |
| 149 | + |
| 150 | + QgsClipboard clipboard; |
| 151 | + clipboard.setData( QStringLiteral( "text/html" ), html.toUtf8(), text ); |
| 152 | + } |
| 153 | +} |
| 154 | + |
124 | 155 | void QgsStatisticalSummaryDockWidget::refreshStatistics()
|
125 | 156 | {
|
126 | 157 | if ( !mLayer || ( mFieldExpressionWidget->isExpression() && !mFieldExpressionWidget->isValidExpression() ) )
|
|
0 commit comments