Skip to content

Commit 486d408

Browse files
committedDec 4, 2014
[FEATURE] Port new memory layer plugin to core
1 parent a435441 commit 486d408

File tree

11 files changed

+481
-0
lines changed

11 files changed

+481
-0
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
<file>themes/default/mActionComposerManager.svg</file>
156156
<file>themes/default/mActionContextHelp.png</file>
157157
<file>themes/default/mActionCopySelected.png</file>
158+
<file>themes/default/mActionCreateMemory.png</file>
158159
<file>themes/default/mActionCustomProjection.svg</file>
159160
<file>themes/default/mActionDecreaseBrightness.svg</file>
160161
<file>themes/default/mActionDecreaseContrast.svg</file>
1.04 KB
Loading

‎python/gui/gui.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
%Include qgsmessagelogviewer.sip
8787
%Include qgsmessageviewer.sip
8888
%Include qgsnewhttpconnection.sip
89+
%Include qgsnewmemorylayerdialog.sip
8990
%Include qgsnewvectorlayerdialog.sip
9091
%Include qgsnumericsortlistviewitem.sip
9192
%Include qgsowssourceselect.sip
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class QgsNewMemoryLayerDialog : QDialog
2+
{
3+
%TypeHeaderCode
4+
#include <qgsnewmemorylayerdialog.h>
5+
%End
6+
7+
public:
8+
9+
/**Runs the dialoag and creates a new memory layer
10+
* @param parent parent widget
11+
* @returns new memory layer
12+
*/
13+
static QgsVectorLayer* runAndCreateLayer( QWidget* parent = 0 );
14+
15+
QgsNewMemoryLayerDialog( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
16+
~QgsNewMemoryLayerDialog();
17+
18+
/**Returns the selected geometry type*/
19+
QGis::WkbType selectedType() const;
20+
21+
/**Returns the selected crs id*/
22+
QString selectedCrsId() const;
23+
24+
/**Returns the layer name*/
25+
QString layerName() const;
26+
27+
protected slots:
28+
29+
void on_mChangeSrsButton_clicked();
30+
};

‎src/app/qgisapp.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
#include "qgsmessagelog.h"
159159
#include "qgsmultibandcolorrenderer.h"
160160
#include "qgsnewvectorlayerdialog.h"
161+
#include "qgsnewmemorylayerdialog.h"
161162
#include "qgsoptions.h"
162163
#include "qgspluginlayer.h"
163164
#include "qgspluginlayerregistry.h"
@@ -1102,6 +1103,7 @@ void QgisApp::createActions()
11021103

11031104
connect( mActionNewVectorLayer, SIGNAL( triggered() ), this, SLOT( newVectorLayer() ) );
11041105
connect( mActionNewSpatiaLiteLayer, SIGNAL( triggered() ), this, SLOT( newSpatialiteLayer() ) );
1106+
connect( mActionNewMemoryLayer, SIGNAL( triggered() ), this, SLOT( newMemoryLayer() ) );
11051107
connect( mActionShowRasterCalculator, SIGNAL( triggered() ), this, SLOT( showRasterCalculator() ) );
11061108
connect( mActionEmbedLayers, SIGNAL( triggered() ), this, SLOT( embedLayers() ) );
11071109
connect( mActionAddLayerDefinition, SIGNAL( triggered() ), this, SLOT( addLayerDefinition() ) );
@@ -1608,12 +1610,14 @@ void QgisApp::createToolBars()
16081610
bt->setPopupMode( QToolButton::MenuButtonPopup );
16091611
bt->addAction( mActionNewSpatiaLiteLayer );
16101612
bt->addAction( mActionNewVectorLayer );
1613+
bt->addAction( mActionNewMemoryLayer );
16111614

16121615
QAction* defNewLayerAction = mActionNewVectorLayer;
16131616
switch ( settings.value( "/UI/defaultNewLayer", 1 ).toInt() )
16141617
{
16151618
case 0: defNewLayerAction = mActionNewSpatiaLiteLayer; break;
16161619
case 1: defNewLayerAction = mActionNewVectorLayer; break;
1620+
case 2: defNewLayerAction = mActionNewMemoryLayer; break;
16171621
}
16181622
bt->setDefaultAction( defNewLayerAction );
16191623
QAction* newLayerAction = mLayerToolBar->addWidget( bt );
@@ -1839,6 +1843,7 @@ void QgisApp::setTheme( QString theThemeName )
18391843
mActionSetLayerCRS->setIcon( QgsApplication::getThemeIcon( "/mActionSetLayerCRS.png" ) );
18401844
mActionSetProjectCRSFromLayer->setIcon( QgsApplication::getThemeIcon( "/mActionSetProjectCRSFromLayer.png" ) );
18411845
mActionNewVectorLayer->setIcon( QgsApplication::getThemeIcon( "/mActionNewVectorLayer.svg" ) );
1846+
mActionNewMemoryLayer->setIcon( QgsApplication::getThemeIcon( "/mActionCreateMemory.png" ) );
18421847
mActionAddAllToOverview->setIcon( QgsApplication::getThemeIcon( "/mActionAddAllToOverview.svg" ) );
18431848
mActionHideAllLayers->setIcon( QgsApplication::getThemeIcon( "/mActionHideAllLayers.png" ) );
18441849
mActionShowAllLayers->setIcon( QgsApplication::getThemeIcon( "/mActionShowAllLayers.png" ) );
@@ -3708,6 +3713,20 @@ void QgisApp::newVectorLayer()
37083713
}
37093714
}
37103715

3716+
void QgisApp::newMemoryLayer()
3717+
{
3718+
QgsVectorLayer* newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this );
3719+
3720+
if ( newLayer )
3721+
{
3722+
//then add the layer to the view
3723+
QList< QgsMapLayer* > layers;
3724+
layers << newLayer;
3725+
3726+
QgsMapLayerRegistry::instance()->addMapLayers( layers );
3727+
}
3728+
}
3729+
37113730
void QgisApp::newSpatialiteLayer()
37123731
{
37133732
QgsNewSpatialiteLayerDialog spatialiteDialog( this );
@@ -10155,6 +10174,8 @@ void QgisApp::toolButtonActionTriggered( QAction *action )
1015510174
settings.setValue( "/UI/defaultNewLayer", 0 );
1015610175
else if ( action == mActionNewVectorLayer )
1015710176
settings.setValue( "/UI/defaultNewLayer", 1 );
10177+
else if ( action == mActionNewMemoryLayer )
10178+
settings.setValue( "/UI/defaultNewLayer", 2 );
1015810179
bt->setDefaultAction( action );
1015910180
}
1016010181

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
882882

883883
//! Create a new empty vector layer
884884
void newVectorLayer();
885+
//! Create a new memory layer
886+
void newMemoryLayer();
885887
//! Create a new empty spatialite layer
886888
void newSpatialiteLayer();
887889
//! Print the current map view frame

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ qgsmessagebaritem.cpp
195195
qgsmessagelogviewer.cpp
196196
qgsmessageviewer.cpp
197197
qgsnewhttpconnection.cpp
198+
qgsnewmemorylayerdialog.cpp
198199
qgsnewvectorlayerdialog.cpp
199200
qgsnumericsortlistviewitem.cpp
200201
qgsoptionsdialogbase.cpp
@@ -392,6 +393,7 @@ qgsmessagebar.h
392393
qgsmessagelogviewer.h
393394
qgsmessageviewer.h
394395
qgsnewhttpconnection.h
396+
qgsnewmemorylayerdialog.h
395397
qgsnewvectorlayerdialog.h
396398
qgsoptionsdialogbase.h
397399
qgsowssourceselect.h

‎src/gui/qgsnewmemorylayerdialog.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
18+
#include "qgsnewmemorylayerdialog.h"
19+
#include "qgsapplication.h"
20+
#include "qgis.h"
21+
#include "qgscoordinatereferencesystem.h"
22+
#include "qgsgenericprojectionselector.h"
23+
#include "qgsproviderregistry.h"
24+
#include "qgsvectordataprovider.h"
25+
26+
#include <QPushButton>
27+
#include <QComboBox>
28+
#include <QLibrary>
29+
#include <QSettings>
30+
#include <QFileDialog>
31+
32+
QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
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.selectedCrsId();
42+
43+
QString geomType;
44+
switch ( geometrytype )
45+
{
46+
case QGis::WKBPoint:
47+
geomType = "point";
48+
break;
49+
case QGis::WKBLineString:
50+
geomType = "linestring";
51+
break;
52+
case QGis::WKBPolygon:
53+
geomType = "polygon";
54+
break;
55+
case QGis::WKBMultiPoint:
56+
geomType = "multipoint";
57+
break;
58+
case QGis::WKBMultiLineString:
59+
geomType = "multilinestring";
60+
break;
61+
case QGis::WKBMultiPolygon:
62+
geomType = "multipolygon";
63+
break;
64+
default:
65+
geomType = "point";
66+
}
67+
68+
QString layerProperties = geomType + QString( "?crs=%1" ).arg( crsId );
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+
84+
QgsCoordinateReferenceSystem srs;
85+
srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
86+
srs.validate();
87+
mCrsId = srs.authid();
88+
mSpatialRefSysEdit->setText( srs.authid() + " - " + srs.description() );
89+
90+
mNameLineEdit->setText( tr( "New scratch layer" ) );
91+
}
92+
93+
QgsNewMemoryLayerDialog::~QgsNewMemoryLayerDialog()
94+
{
95+
QSettings settings;
96+
settings.setValue( "/Windows/NewMemoryLayer/geometry", saveGeometry() );
97+
}
98+
99+
QGis::WkbType QgsNewMemoryLayerDialog::selectedType() const
100+
{
101+
if ( mPointRadioButton->isChecked() )
102+
{
103+
return QGis::WKBPoint;
104+
}
105+
else if ( mLineRadioButton->isChecked() )
106+
{
107+
return QGis::WKBLineString;
108+
}
109+
else if ( mPolygonRadioButton->isChecked() )
110+
{
111+
return QGis::WKBPolygon;
112+
}
113+
else if ( mMultiPointRadioButton->isChecked() )
114+
{
115+
return QGis::WKBMultiPoint;
116+
}
117+
else if ( mMultiLineRadioButton->isChecked() )
118+
{
119+
return QGis::WKBMultiLineString;
120+
}
121+
else if ( mMultiPolygonRadioButton->isChecked() )
122+
{
123+
return QGis::WKBMultiPolygon;
124+
}
125+
return QGis::WKBUnknown;
126+
}
127+
128+
QString QgsNewMemoryLayerDialog::layerName() const
129+
{
130+
return mNameLineEdit->text();
131+
}
132+
133+
QString QgsNewMemoryLayerDialog::selectedCrsId() const
134+
{
135+
return mCrsId;
136+
}
137+
138+
void QgsNewMemoryLayerDialog::on_mChangeSrsButton_clicked()
139+
{
140+
QgsGenericProjectionSelector *selector = new QgsGenericProjectionSelector( this );
141+
selector->setMessage();
142+
selector->setSelectedAuthId( mCrsId );
143+
if ( selector->exec() )
144+
{
145+
mCrsId = selector->selectedAuthId();
146+
mSpatialRefSysEdit->setText( mCrsId );
147+
}
148+
else
149+
{
150+
QApplication::restoreOverrideCursor();
151+
}
152+
delete selector;
153+
}

‎src/gui/qgsnewmemorylayerdialog.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/***************************************************************************
2+
qgsnewmemorylayerdialog.h
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+
#ifndef QGSNEWMEMORYLAYERDIALOG_H
18+
#define QGSNEWMEMORYLAYERDIALOG_H
19+
20+
#include "ui_qgsnewmemorylayerdialogbase.h"
21+
#include "qgisgui.h"
22+
#include "qgis.h"
23+
#include "qgsvectorlayer.h"
24+
25+
class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemoryLayerDialogBase
26+
{
27+
Q_OBJECT
28+
29+
public:
30+
31+
/**Runs the dialoag and creates a new memory layer
32+
* @param parent parent widget
33+
* @returns new memory layer
34+
*/
35+
static QgsVectorLayer* runAndCreateLayer( QWidget* parent = 0 );
36+
37+
QgsNewMemoryLayerDialog( QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
38+
~QgsNewMemoryLayerDialog();
39+
40+
/**Returns the selected geometry type*/
41+
QGis::WkbType selectedType() const;
42+
43+
/**Returns the selected crs id*/
44+
QString selectedCrsId() const;
45+
46+
/**Returns the layer name*/
47+
QString layerName() const;
48+
49+
protected slots:
50+
51+
void on_mChangeSrsButton_clicked();
52+
53+
private:
54+
QString mCrsId;
55+
};
56+
57+
#endif //QGSNEWMEMORYLAYERDIALOG_H

‎src/ui/qgisapp.ui

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
</property>
132132
<addaction name="mActionNewVectorLayer"/>
133133
<addaction name="mActionNewSpatiaLiteLayer"/>
134+
<addaction name="mActionNewMemoryLayer"/>
134135
</widget>
135136
<widget class="QMenu" name="mAddLayerMenu">
136137
<property name="title">
@@ -2270,6 +2271,18 @@ Acts on currently active editable layer</string>
22702271
<string>Hide Selected Layers</string>
22712272
</property>
22722273
</action>
2274+
<action name="mActionNewMemoryLayer">
2275+
<property name="icon">
2276+
<iconset resource="../../images/images.qrc">
2277+
<normaloff>:/images/themes/default/mActionCreateMemory.png</normaloff>:/images/themes/default/mActionCreateMemory.png</iconset>
2278+
</property>
2279+
<property name="text">
2280+
<string>New Temporary Scratch Layer...</string>
2281+
</property>
2282+
<property name="toolTip">
2283+
<string>New temporary scratch layer</string>
2284+
</property>
2285+
</action>
22732286
</widget>
22742287
<resources>
22752288
<include location="../../images/images.qrc"/>

‎src/ui/qgsnewmemorylayerdialogbase.ui

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsNewMemoryLayerDialogBase</class>
4+
<widget class="QDialog" name="QgsNewMemoryLayerDialogBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>444</width>
10+
<height>255</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="windowTitle">
20+
<string>New Temporary Scratch Layer</string>
21+
</property>
22+
<property name="modal">
23+
<bool>true</bool>
24+
</property>
25+
<layout class="QVBoxLayout" name="verticalLayout">
26+
<item>
27+
<layout class="QHBoxLayout" name="horizontalLayout_2">
28+
<item>
29+
<widget class="QLabel" name="label">
30+
<property name="text">
31+
<string>Layer name</string>
32+
</property>
33+
</widget>
34+
</item>
35+
<item>
36+
<widget class="QLineEdit" name="mNameLineEdit"/>
37+
</item>
38+
</layout>
39+
</item>
40+
<item>
41+
<widget class="QGroupBox" name="buttonGroup1">
42+
<property name="title">
43+
<string>Type</string>
44+
</property>
45+
<layout class="QGridLayout" name="gridLayout">
46+
<item row="0" column="0">
47+
<widget class="QRadioButton" name="mPointRadioButton">
48+
<property name="text">
49+
<string>Point</string>
50+
</property>
51+
</widget>
52+
</item>
53+
<item row="0" column="1">
54+
<widget class="QRadioButton" name="mLineRadioButton">
55+
<property name="text">
56+
<string>Line</string>
57+
</property>
58+
</widget>
59+
</item>
60+
<item row="0" column="2">
61+
<widget class="QRadioButton" name="mPolygonRadioButton">
62+
<property name="text">
63+
<string>Polygon</string>
64+
</property>
65+
</widget>
66+
</item>
67+
<item row="1" column="0">
68+
<widget class="QRadioButton" name="mMultiPointRadioButton">
69+
<property name="text">
70+
<string>Multipoint</string>
71+
</property>
72+
</widget>
73+
</item>
74+
<item row="1" column="1">
75+
<widget class="QRadioButton" name="mMultiLineRadioButton">
76+
<property name="text">
77+
<string>Multiline</string>
78+
</property>
79+
</widget>
80+
</item>
81+
<item row="1" column="2">
82+
<widget class="QRadioButton" name="mMultiPolygonRadioButton">
83+
<property name="text">
84+
<string>Multipolygon</string>
85+
</property>
86+
</widget>
87+
</item>
88+
</layout>
89+
</widget>
90+
</item>
91+
<item>
92+
<layout class="QHBoxLayout" name="horizontalLayout_3">
93+
<item>
94+
<widget class="QLineEdit" name="mSpatialRefSysEdit">
95+
<property name="readOnly">
96+
<bool>true</bool>
97+
</property>
98+
</widget>
99+
</item>
100+
<item>
101+
<widget class="QPushButton" name="mChangeSrsButton">
102+
<property name="toolTip">
103+
<string>Specify the coordinate reference system of the layer's geometry.</string>
104+
</property>
105+
<property name="whatsThis">
106+
<string>Specify the coordinate reference system of the layer's geometry.</string>
107+
</property>
108+
<property name="text">
109+
<string>Specify CRS</string>
110+
</property>
111+
</widget>
112+
</item>
113+
</layout>
114+
</item>
115+
<item>
116+
<widget class="QLabel" name="label_2">
117+
<property name="text">
118+
<string>&lt;i&gt;&lt;b&gt;Warning:&lt;/b&gt; Temporary scratch layers are not saved and will be discarded when QGIS is closed.&lt;/i&gt;</string>
119+
</property>
120+
<property name="textFormat">
121+
<enum>Qt::AutoText</enum>
122+
</property>
123+
<property name="wordWrap">
124+
<bool>true</bool>
125+
</property>
126+
</widget>
127+
</item>
128+
<item>
129+
<spacer name="verticalSpacer">
130+
<property name="orientation">
131+
<enum>Qt::Vertical</enum>
132+
</property>
133+
<property name="sizeHint" stdset="0">
134+
<size>
135+
<width>20</width>
136+
<height>40</height>
137+
</size>
138+
</property>
139+
</spacer>
140+
</item>
141+
<item>
142+
<widget class="QDialogButtonBox" name="mButtonBox">
143+
<property name="orientation">
144+
<enum>Qt::Horizontal</enum>
145+
</property>
146+
<property name="standardButtons">
147+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
148+
</property>
149+
</widget>
150+
</item>
151+
</layout>
152+
</widget>
153+
<layoutdefault spacing="6" margin="11"/>
154+
<tabstops>
155+
<tabstop>mNameLineEdit</tabstop>
156+
<tabstop>mPointRadioButton</tabstop>
157+
<tabstop>mLineRadioButton</tabstop>
158+
<tabstop>mPolygonRadioButton</tabstop>
159+
<tabstop>mMultiPointRadioButton</tabstop>
160+
<tabstop>mMultiLineRadioButton</tabstop>
161+
<tabstop>mMultiPolygonRadioButton</tabstop>
162+
<tabstop>mSpatialRefSysEdit</tabstop>
163+
<tabstop>mChangeSrsButton</tabstop>
164+
<tabstop>mButtonBox</tabstop>
165+
</tabstops>
166+
<resources/>
167+
<connections>
168+
<connection>
169+
<sender>mButtonBox</sender>
170+
<signal>accepted()</signal>
171+
<receiver>QgsNewMemoryLayerDialogBase</receiver>
172+
<slot>accept()</slot>
173+
<hints>
174+
<hint type="sourcelabel">
175+
<x>349</x>
176+
<y>400</y>
177+
</hint>
178+
<hint type="destinationlabel">
179+
<x>387</x>
180+
<y>304</y>
181+
</hint>
182+
</hints>
183+
</connection>
184+
<connection>
185+
<sender>mButtonBox</sender>
186+
<signal>rejected()</signal>
187+
<receiver>QgsNewMemoryLayerDialogBase</receiver>
188+
<slot>reject()</slot>
189+
<hints>
190+
<hint type="sourcelabel">
191+
<x>275</x>
192+
<y>400</y>
193+
</hint>
194+
<hint type="destinationlabel">
195+
<x>242</x>
196+
<y>308</y>
197+
</hint>
198+
</hints>
199+
</connection>
200+
</connections>
201+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.