-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgeometrycheckerfixsummarydialog.cpp
130 lines (112 loc) · 5.99 KB
/
qgsgeometrycheckerfixsummarydialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
* qgsgeometrycheckerfixsummarydialog.cpp *
* ------------------- *
* copyright : (C) 2015 by Sandro Mani / Sourcepole AG *
* email : smani@sourcepole.ch *
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsgeometrycheckerfixsummarydialog.h"
#include "qgsgeometrychecker.h"
#include "qgsgeometrycheck.h"
#include "qgsfeaturepool.h"
#include "qgisinterface.h"
#include "qgsmapcanvas.h"
QgsGeometryCheckerFixSummaryDialog::QgsGeometryCheckerFixSummaryDialog( const Statistics &stats, QgsGeometryChecker *checker, QWidget *parent )
: QDialog( parent )
, mChecker( checker )
{
ui.setupUi( this );
ui.groupBoxFixedErrors->setTitle( tr( "%1 errors were fixed" ).arg( stats.fixedErrors.size() ) );
ui.groupBoxNewErrors->setTitle( tr( "%1 new errors were found" ).arg( stats.newErrors.count() ) );
ui.groupBoxNotFixed->setTitle( tr( "%1 errors were not fixed" ).arg( stats.failedErrors.count() ) );
ui.groupBoxObsoleteErrors->setTitle( tr( "%1 errors are obsolete" ).arg( stats.obsoleteErrors.count() ) );
for ( QgsGeometryCheckError *error : stats.fixedErrors )
{
addError( ui.tableWidgetFixedErrors, error );
}
for ( QgsGeometryCheckError *error : stats.newErrors )
{
addError( ui.tableWidgetNewErrors, error );
}
for ( QgsGeometryCheckError *error : stats.failedErrors )
{
addError( ui.tableWidgetNotFixed, error );
}
for ( QgsGeometryCheckError *error : stats.obsoleteErrors )
{
addError( ui.tableWidgetObsoleteErrors, error );
}
setupTable( ui.tableWidgetFixedErrors );
setupTable( ui.tableWidgetNewErrors );
setupTable( ui.tableWidgetNotFixed );
setupTable( ui.tableWidgetObsoleteErrors );
ui.plainTextEditMessages->setPlainText( checker->getMessages().join( QStringLiteral( "\n" ) ) );
ui.groupBoxFixedErrors->setVisible( !stats.fixedErrors.isEmpty() );
ui.groupBoxNewErrors->setVisible( !stats.newErrors.isEmpty() );
ui.groupBoxNotFixed->setVisible( !stats.failedErrors.isEmpty() );
ui.groupBoxObsoleteErrors->setVisible( !stats.obsoleteErrors.isEmpty() );
ui.groupBoxMessages->setVisible( !checker->getMessages().isEmpty() );
}
void QgsGeometryCheckerFixSummaryDialog::addError( QTableWidget *table, QgsGeometryCheckError *error )
{
bool sortingWasEnabled = table->isSortingEnabled();
if ( sortingWasEnabled )
table->setSortingEnabled( false );
int prec = 7 - std::floor( std::max( 0., std::log10( std::max( error->location().x(), error->location().y() ) ) ) );
QString posStr = QStringLiteral( "%1, %2" ).arg( error->location().x(), 0, 'f', prec ).arg( error->location().y(), 0, 'f', prec );
int row = table->rowCount();
table->insertRow( row );
table->setItem( row, 0, new QTableWidgetItem( !error->layerId().isEmpty() ? mChecker->getContext()->featurePools[error->layerId()]->getLayer()->name() : "" ) );
QTableWidgetItem *idItem = new QTableWidgetItem();
idItem->setData( Qt::EditRole, error->featureId() != FEATUREID_NULL ? QVariant( error->featureId() ) : QVariant() );
table->setItem( row, 1, idItem );
table->setItem( row, 2, new QTableWidgetItem( error->description() ) );
table->setItem( row, 3, new QTableWidgetItem( posStr ) );
QTableWidgetItem *valueItem = new QTableWidgetItem();
valueItem->setData( Qt::EditRole, error->value() );
table->setItem( row, 4, valueItem );
table->item( row, 0 )->setData( Qt::UserRole, QVariant::fromValue( reinterpret_cast<void *>( error ) ) );
if ( sortingWasEnabled )
table->setSortingEnabled( true );
}
void QgsGeometryCheckerFixSummaryDialog::setupTable( QTableWidget *table )
{
table->resizeColumnToContents( 0 );
table->resizeColumnToContents( 1 );
table->horizontalHeader()->setResizeMode( 2, QHeaderView::Stretch );
table->horizontalHeader()->setResizeMode( 3, QHeaderView::Stretch );
table->horizontalHeader()->setResizeMode( 4, QHeaderView::Stretch );
table->setEditTriggers( QAbstractItemView::NoEditTriggers );
table->setSelectionBehavior( QAbstractItemView::SelectRows );
table->setSelectionMode( QAbstractItemView::SingleSelection );
table->horizontalHeader()->setSortIndicator( 0, Qt::AscendingOrder );
table->setSortingEnabled( true );
connect( table->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsGeometryCheckerFixSummaryDialog::onTableSelectionChanged );
}
void QgsGeometryCheckerFixSummaryDialog::onTableSelectionChanged( const QItemSelection &newSel, const QItemSelection & /*oldSel*/ )
{
QItemSelectionModel *selModel = qobject_cast<QItemSelectionModel *>( QObject::sender() );
const QAbstractItemModel *model = selModel->model();
for ( QTableWidget *table : {ui.tableWidgetFixedErrors, ui.tableWidgetNewErrors, ui.tableWidgetNotFixed, ui.tableWidgetObsoleteErrors} )
{
if ( table->selectionModel() != selModel )
{
table->selectionModel()->blockSignals( true );
table->clearSelection();
table->selectionModel()->blockSignals( false );
}
}
if ( !newSel.isEmpty() && !newSel.first().indexes().isEmpty() )
{
QModelIndex idx = newSel.first().indexes().first();
QgsGeometryCheckError *error = reinterpret_cast<QgsGeometryCheckError *>( model->data( model->index( idx.row(), 0 ), Qt::UserRole ).value<void *>() );
emit errorSelected( error );
}
}