/
qgsgeometrycheckerdialog.cpp
106 lines (90 loc) · 4.11 KB
/
qgsgeometrycheckerdialog.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
/***************************************************************************
* qgsgeometrycheckerdialog.cpp *
* ------------------- *
* copyright : (C) 2014 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 "qgsgeometrycheckerdialog.h"
#include "qgsgeometrycheckersetuptab.h"
#include "qgsgeometrycheckerresulttab.h"
#include "../qgsgeometrychecker.h"
#include "../utils/qgsfeaturepool.h"
#include "qgssettings.h"
#include <QCloseEvent>
#include <QVBoxLayout>
QgsGeometryCheckerDialog::QgsGeometryCheckerDialog( QgisInterface *iface, QWidget *parent )
: QDialog( parent )
{
mIface = iface;
setWindowTitle( tr( "Check Geometries" ) );
QgsSettings s;
restoreGeometry( s.value( QStringLiteral( "/Plugin-GeometryChecker/Window/geometry" ) ).toByteArray() );
mTabWidget = new QTabWidget();
mButtonBox = new QDialogButtonBox( QDialogButtonBox::Close | QDialogButtonBox::Help, Qt::Horizontal );
QVBoxLayout *layout = new QVBoxLayout( this );
layout->addWidget( mTabWidget );
layout->addWidget( mButtonBox );
mTabWidget->addTab( new QgsGeometryCheckerSetupTab( iface, this ), tr( "Setup" ) );
mTabWidget->addTab( new QWidget(), tr( "Result" ) );
mTabWidget->setTabEnabled( 1, false );
resize( 640, 640 );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsGeometryCheckerDialog::showHelp );
connect( dynamic_cast< QgsGeometryCheckerSetupTab * >( mTabWidget->widget( 0 ) ), &QgsGeometryCheckerSetupTab::checkerStarted, this, &QgsGeometryCheckerDialog::onCheckerStarted );
connect( dynamic_cast< QgsGeometryCheckerSetupTab * >( mTabWidget->widget( 0 ) ), &QgsGeometryCheckerSetupTab::checkerFinished, this, &QgsGeometryCheckerDialog::onCheckerFinished );
}
QgsGeometryCheckerDialog::~QgsGeometryCheckerDialog()
{
QgsSettings s;
s.setValue( QStringLiteral( "/Plugin-GeometryChecker/Window/geometry" ), saveGeometry() );
}
void QgsGeometryCheckerDialog::onCheckerStarted( QgsGeometryChecker *checker )
{
delete mTabWidget->widget( 1 );
mTabWidget->removeTab( 1 );
mTabWidget->addTab( new QgsGeometryCheckerResultTab( mIface, checker, mTabWidget ), tr( "Result" ) );
mTabWidget->setTabEnabled( 1, false );
mButtonBox->button( QDialogButtonBox::Close )->setEnabled( false );
}
void QgsGeometryCheckerDialog::onCheckerFinished( bool successful )
{
mButtonBox->button( QDialogButtonBox::Close )->setEnabled( true );
if ( successful )
{
mTabWidget->setTabEnabled( 1, true );
mTabWidget->setCurrentIndex( 1 );
static_cast<QgsGeometryCheckerResultTab *>( mTabWidget->widget( 1 ) )->finalize();
}
}
void QgsGeometryCheckerDialog::done( int r )
{
QDialog::done( r );
delete mTabWidget->widget( 1 );
mTabWidget->removeTab( 1 );
mTabWidget->addTab( new QWidget(), tr( "Result" ) );
mTabWidget->setTabEnabled( 1, false );
}
void QgsGeometryCheckerDialog::closeEvent( QCloseEvent *ev )
{
if ( qobject_cast<QgsGeometryCheckerResultTab *>( mTabWidget->widget( 1 ) ) &&
!static_cast<QgsGeometryCheckerResultTab *>( mTabWidget->widget( 1 ) )->isCloseable() )
{
ev->ignore();
}
else
{
QDialog::closeEvent( ev );
}
}
void QgsGeometryCheckerDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "plugins/plugins_geometry_checker.html" ) );
}