Skip to content
Permalink
Browse files

[FEATURE] Port new memory layer plugin to core

  • Loading branch information
nyalldawson committed Dec 4, 2014
1 parent a435441 commit 486d4086310d2466d8c4f5cc4f4eb8f6aa16b7e9
@@ -155,6 +155,7 @@
<file>themes/default/mActionComposerManager.svg</file>
<file>themes/default/mActionContextHelp.png</file>
<file>themes/default/mActionCopySelected.png</file>
<file>themes/default/mActionCreateMemory.png</file>
<file>themes/default/mActionCustomProjection.svg</file>
<file>themes/default/mActionDecreaseBrightness.svg</file>
<file>themes/default/mActionDecreaseContrast.svg</file>
Binary file not shown.
@@ -86,6 +86,7 @@
%Include qgsmessagelogviewer.sip
%Include qgsmessageviewer.sip
%Include qgsnewhttpconnection.sip
%Include qgsnewmemorylayerdialog.sip
%Include qgsnewvectorlayerdialog.sip
%Include qgsnumericsortlistviewitem.sip
%Include qgsowssourceselect.sip
@@ -0,0 +1,30 @@
class QgsNewMemoryLayerDialog : QDialog
{
%TypeHeaderCode
#include <qgsnewmemorylayerdialog.h>
%End

public:

/**Runs the dialoag and creates a new memory layer
* @param parent parent widget
* @returns new memory layer
*/
static QgsVectorLayer* runAndCreateLayer( QWidget* parent = 0 );

QgsNewMemoryLayerDialog( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
~QgsNewMemoryLayerDialog();

/**Returns the selected geometry type*/
QGis::WkbType selectedType() const;

/**Returns the selected crs id*/
QString selectedCrsId() const;

/**Returns the layer name*/
QString layerName() const;

protected slots:

void on_mChangeSrsButton_clicked();
};
@@ -158,6 +158,7 @@
#include "qgsmessagelog.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsnewvectorlayerdialog.h"
#include "qgsnewmemorylayerdialog.h"
#include "qgsoptions.h"
#include "qgspluginlayer.h"
#include "qgspluginlayerregistry.h"
@@ -1102,6 +1103,7 @@ void QgisApp::createActions()

connect( mActionNewVectorLayer, SIGNAL( triggered() ), this, SLOT( newVectorLayer() ) );
connect( mActionNewSpatiaLiteLayer, SIGNAL( triggered() ), this, SLOT( newSpatialiteLayer() ) );
connect( mActionNewMemoryLayer, SIGNAL( triggered() ), this, SLOT( newMemoryLayer() ) );
connect( mActionShowRasterCalculator, SIGNAL( triggered() ), this, SLOT( showRasterCalculator() ) );
connect( mActionEmbedLayers, SIGNAL( triggered() ), this, SLOT( embedLayers() ) );
connect( mActionAddLayerDefinition, SIGNAL( triggered() ), this, SLOT( addLayerDefinition() ) );
@@ -1608,12 +1610,14 @@ void QgisApp::createToolBars()
bt->setPopupMode( QToolButton::MenuButtonPopup );
bt->addAction( mActionNewSpatiaLiteLayer );
bt->addAction( mActionNewVectorLayer );
bt->addAction( mActionNewMemoryLayer );

QAction* defNewLayerAction = mActionNewVectorLayer;
switch ( settings.value( "/UI/defaultNewLayer", 1 ).toInt() )
{
case 0: defNewLayerAction = mActionNewSpatiaLiteLayer; break;
case 1: defNewLayerAction = mActionNewVectorLayer; break;
case 2: defNewLayerAction = mActionNewMemoryLayer; break;
}
bt->setDefaultAction( defNewLayerAction );
QAction* newLayerAction = mLayerToolBar->addWidget( bt );
@@ -1839,6 +1843,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionSetLayerCRS->setIcon( QgsApplication::getThemeIcon( "/mActionSetLayerCRS.png" ) );
mActionSetProjectCRSFromLayer->setIcon( QgsApplication::getThemeIcon( "/mActionSetProjectCRSFromLayer.png" ) );
mActionNewVectorLayer->setIcon( QgsApplication::getThemeIcon( "/mActionNewVectorLayer.svg" ) );
mActionNewMemoryLayer->setIcon( QgsApplication::getThemeIcon( "/mActionCreateMemory.png" ) );
mActionAddAllToOverview->setIcon( QgsApplication::getThemeIcon( "/mActionAddAllToOverview.svg" ) );
mActionHideAllLayers->setIcon( QgsApplication::getThemeIcon( "/mActionHideAllLayers.png" ) );
mActionShowAllLayers->setIcon( QgsApplication::getThemeIcon( "/mActionShowAllLayers.png" ) );
@@ -3708,6 +3713,20 @@ void QgisApp::newVectorLayer()
}
}

void QgisApp::newMemoryLayer()
{
QgsVectorLayer* newLayer = QgsNewMemoryLayerDialog::runAndCreateLayer( this );

if ( newLayer )
{
//then add the layer to the view
QList< QgsMapLayer* > layers;
layers << newLayer;

QgsMapLayerRegistry::instance()->addMapLayers( layers );
}
}

void QgisApp::newSpatialiteLayer()
{
QgsNewSpatialiteLayerDialog spatialiteDialog( this );
@@ -10155,6 +10174,8 @@ void QgisApp::toolButtonActionTriggered( QAction *action )
settings.setValue( "/UI/defaultNewLayer", 0 );
else if ( action == mActionNewVectorLayer )
settings.setValue( "/UI/defaultNewLayer", 1 );
else if ( action == mActionNewMemoryLayer )
settings.setValue( "/UI/defaultNewLayer", 2 );
bt->setDefaultAction( action );
}

@@ -882,6 +882,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

//! Create a new empty vector layer
void newVectorLayer();
//! Create a new memory layer
void newMemoryLayer();
//! Create a new empty spatialite layer
void newSpatialiteLayer();
//! Print the current map view frame
@@ -195,6 +195,7 @@ qgsmessagebaritem.cpp
qgsmessagelogviewer.cpp
qgsmessageviewer.cpp
qgsnewhttpconnection.cpp
qgsnewmemorylayerdialog.cpp
qgsnewvectorlayerdialog.cpp
qgsnumericsortlistviewitem.cpp
qgsoptionsdialogbase.cpp
@@ -392,6 +393,7 @@ qgsmessagebar.h
qgsmessagelogviewer.h
qgsmessageviewer.h
qgsnewhttpconnection.h
qgsnewmemorylayerdialog.h
qgsnewvectorlayerdialog.h
qgsoptionsdialogbase.h
qgsowssourceselect.h
@@ -0,0 +1,153 @@
/***************************************************************************
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 "qgsgenericprojectionselector.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.selectedCrsId();

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";
}

QString layerProperties = geomType + QString( "?crs=%1" ).arg( crsId );
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 srs;
srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
srs.validate();
mCrsId = srs.authid();
mSpatialRefSysEdit->setText( srs.authid() + " - " + srs.description() );

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;
}

QString QgsNewMemoryLayerDialog::layerName() const
{
return mNameLineEdit->text();
}

QString QgsNewMemoryLayerDialog::selectedCrsId() const
{
return mCrsId;
}

void QgsNewMemoryLayerDialog::on_mChangeSrsButton_clicked()
{
QgsGenericProjectionSelector *selector = new QgsGenericProjectionSelector( this );
selector->setMessage();
selector->setSelectedAuthId( mCrsId );
if ( selector->exec() )
{
mCrsId = selector->selectedAuthId();
mSpatialRefSysEdit->setText( mCrsId );
}
else
{
QApplication::restoreOverrideCursor();
}
delete selector;
}
@@ -0,0 +1,57 @@
/***************************************************************************
qgsnewmemorylayerdialog.h
-------------------
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. *
* *
***************************************************************************/
#ifndef QGSNEWMEMORYLAYERDIALOG_H
#define QGSNEWMEMORYLAYERDIALOG_H

#include "ui_qgsnewmemorylayerdialogbase.h"
#include "qgisgui.h"
#include "qgis.h"
#include "qgsvectorlayer.h"

class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemoryLayerDialogBase
{
Q_OBJECT

public:

/**Runs the dialoag and creates a new memory layer
* @param parent parent widget
* @returns new memory layer
*/
static QgsVectorLayer* runAndCreateLayer( QWidget* parent = 0 );

QgsNewMemoryLayerDialog( QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
~QgsNewMemoryLayerDialog();

/**Returns the selected geometry type*/
QGis::WkbType selectedType() const;

/**Returns the selected crs id*/
QString selectedCrsId() const;

/**Returns the layer name*/
QString layerName() const;

protected slots:

void on_mChangeSrsButton_clicked();

private:
QString mCrsId;
};

#endif //QGSNEWMEMORYLAYERDIALOG_H
@@ -131,6 +131,7 @@
</property>
<addaction name="mActionNewVectorLayer"/>
<addaction name="mActionNewSpatiaLiteLayer"/>
<addaction name="mActionNewMemoryLayer"/>
</widget>
<widget class="QMenu" name="mAddLayerMenu">
<property name="title">
@@ -2270,6 +2271,18 @@ Acts on currently active editable layer</string>
<string>Hide Selected Layers</string>
</property>
</action>
<action name="mActionNewMemoryLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionCreateMemory.png</normaloff>:/images/themes/default/mActionCreateMemory.png</iconset>
</property>
<property name="text">
<string>New Temporary Scratch Layer...</string>
</property>
<property name="toolTip">
<string>New temporary scratch layer</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 486d408

Please sign in to comment.
You can’t perform that action at this time.