QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsnewmemorylayerdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnewmemorylayerdialog.cpp
3  -------------------
4  begin : September 2014
5  copyright : (C) 2014 by Nyall Dawson, Marco Hugentobler
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsapplication.h"
20 #include "qgis.h"
22 #include "qgsproviderregistry.h"
23 #include "qgsvectordataprovider.h"
24 
25 #include <QPushButton>
26 #include <QComboBox>
27 #include <QLibrary>
28 #include <QSettings>
29 #include <QUuid>
30 #include <QFileDialog>
31 
33 {
34  QgsNewMemoryLayerDialog dialog( parent );
35  if ( dialog.exec() == QDialog::Rejected )
36  {
37  return 0;
38  }
39 
40  QGis::WkbType geometrytype = dialog.selectedType();
41  QString crsId = dialog.crs().authid();
42 
43  QString geomType;
44  switch ( geometrytype )
45  {
46  case QGis::WKBPoint:
47  geomType = "point";
48  break;
50  geomType = "linestring";
51  break;
52  case QGis::WKBPolygon:
53  geomType = "polygon";
54  break;
56  geomType = "multipoint";
57  break;
59  geomType = "multilinestring";
60  break;
62  geomType = "multipolygon";
63  break;
64  default:
65  geomType = "point";
66  }
67 
68  QString layerProperties = QString( "%1?crs=%2&memoryid=%3" ).arg( geomType ).arg( crsId ).arg( QUuid::createUuid().toString() );
69  QString name = dialog.layerName().isEmpty() ? tr( "New scratch layer" ) : dialog.layerName();
70  QgsVectorLayer* newLayer = new QgsVectorLayer( layerProperties, name, QString( "memory" ) );
71  return newLayer;
72 }
73 
74 QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFlags fl )
75  : QDialog( parent, fl )
76 {
77  setupUi( this );
78 
79  QSettings settings;
80  restoreGeometry( settings.value( "/Windows/NewMemoryLayer/geometry" ).toByteArray() );
81 
82  mPointRadioButton->setChecked( true );
83 
85  defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
86  defaultCrs.validate();
87  mCrsSelector->setCrs( defaultCrs );
88 
89  mNameLineEdit->setText( tr( "New scratch layer" ) );
90 }
91 
93 {
94  QSettings settings;
95  settings.setValue( "/Windows/NewMemoryLayer/geometry", saveGeometry() );
96 }
97 
99 {
100  if ( mPointRadioButton->isChecked() )
101  {
102  return QGis::WKBPoint;
103  }
104  else if ( mLineRadioButton->isChecked() )
105  {
106  return QGis::WKBLineString;
107  }
108  else if ( mPolygonRadioButton->isChecked() )
109  {
110  return QGis::WKBPolygon;
111  }
112  else if ( mMultiPointRadioButton->isChecked() )
113  {
114  return QGis::WKBMultiPoint;
115  }
116  else if ( mMultiLineRadioButton->isChecked() )
117  {
119  }
120  else if ( mMultiPolygonRadioButton->isChecked() )
121  {
122  return QGis::WKBMultiPolygon;
123  }
124  return QGis::WKBUnknown;
125 }
126 
128 {
129  return mCrsSelector->crs();
130 }
131 
133 {
134  return mNameLineEdit->text();
135 }