/
qgsnewmemorylayerdialog.cpp
135 lines (119 loc) · 4 KB
/
qgsnewmemorylayerdialog.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
131
132
133
134
135
/***************************************************************************
qgsnewmemorylayerdialog.cpp
-------------------
begin : September 2014
copyright : (C) 2014 by Nyall Dawson, Marco Hugentobler
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* 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 "qgsnewmemorylayerdialog.h"
#include "qgsapplication.h"
#include "qgis.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsproviderregistry.h"
#include "qgsvectordataprovider.h"
#include <QPushButton>
#include <QComboBox>
#include <QLibrary>
#include <QSettings>
#include <QFileDialog>
QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
{
QgsNewMemoryLayerDialog dialog( parent );
if ( dialog.exec() == QDialog::Rejected )
{
return 0;
}
QGis::WkbType geometrytype = dialog.selectedType();
QString crsId = dialog.crs().authid();
QString geomType;
switch ( geometrytype )
{
case QGis::WKBPoint:
geomType = "point";
break;
case QGis::WKBLineString:
geomType = "linestring";
break;
case QGis::WKBPolygon:
geomType = "polygon";
break;
case QGis::WKBMultiPoint:
geomType = "multipoint";
break;
case QGis::WKBMultiLineString:
geomType = "multilinestring";
break;
case QGis::WKBMultiPolygon:
geomType = "multipolygon";
break;
default:
geomType = "point";
}
static int createScratchLayers = 0;
QString layerProperties = QString( "%1?crs=%2&memoryid=scratchlayer%3" ).arg( geomType ).arg( crsId ).arg( ++createScratchLayers );
QString name = dialog.layerName().isEmpty() ? tr( "New scratch layer" ) : dialog.layerName();
QgsVectorLayer* newLayer = new QgsVectorLayer( layerProperties, name, QString( "memory" ) );
return newLayer;
}
QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
QSettings settings;
restoreGeometry( settings.value( "/Windows/NewMemoryLayer/geometry" ).toByteArray() );
mPointRadioButton->setChecked( true );
QgsCoordinateReferenceSystem defaultCrs;
defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
defaultCrs.validate();
mCrsSelector->setCrs( defaultCrs );
mNameLineEdit->setText( tr( "New scratch layer" ) );
}
QgsNewMemoryLayerDialog::~QgsNewMemoryLayerDialog()
{
QSettings settings;
settings.setValue( "/Windows/NewMemoryLayer/geometry", saveGeometry() );
}
QGis::WkbType QgsNewMemoryLayerDialog::selectedType() const
{
if ( mPointRadioButton->isChecked() )
{
return QGis::WKBPoint;
}
else if ( mLineRadioButton->isChecked() )
{
return QGis::WKBLineString;
}
else if ( mPolygonRadioButton->isChecked() )
{
return QGis::WKBPolygon;
}
else if ( mMultiPointRadioButton->isChecked() )
{
return QGis::WKBMultiPoint;
}
else if ( mMultiLineRadioButton->isChecked() )
{
return QGis::WKBMultiLineString;
}
else if ( mMultiPolygonRadioButton->isChecked() )
{
return QGis::WKBMultiPolygon;
}
return QGis::WKBUnknown;
}
QgsCoordinateReferenceSystem QgsNewMemoryLayerDialog::crs() const
{
return mCrsSelector->crs();
}
QString QgsNewMemoryLayerDialog::layerName() const
{
return mNameLineEdit->text();
}