QGIS API Documentation  2.12.0-Lyon
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, crsId, 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 
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 }
QGis::WkbType selectedType() const
Returns the selected geometry type.
QByteArray toByteArray() const
void setupUi(QWidget *widget)
void validate()
Perform some validation on this CRS.
int exec()
WkbType
Used for symbology operations.
Definition: qgis.h:56
QString tr(const char *sourceText, const char *disambiguation, int n)
void setValue(const QString &key, const QVariant &value)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
const char * name() const
bool restoreGeometry(const QByteArray &geometry)
QgsNewMemoryLayerDialog(QWidget *parent=0, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
bool isEmpty() const
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:73
QString layerName() const
Returns the layer name.
QVariant value(const QString &key, const QVariant &defaultValue) const
QByteArray saveGeometry() const
Class for storing a coordinate reference system (CRS)
QString authid() const
Get the authority identifier for this srs.
QgsCoordinateReferenceSystem crs() const
Returns the selected crs.
static QgsVectorLayer * runAndCreateLayer(QWidget *parent=0)
Runs the dialoag and creates a new memory layer.
typedef WindowFlags
Represents a vector layer which manages a vector based data sets.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
QUuid createUuid()