Skip to content
Permalink
Browse files

move delimitedtext plugin functionality to the provider (fix #6013):

allow GUI and provider to use the same splitLine method.
  • Loading branch information
brushtyler committed Jul 15, 2012
1 parent 2278f40 commit beb70d3175d9995804ffe178e57368224cc9576e
@@ -2,17 +2,9 @@
########################################################
# Files

SET (DLTEXT_SRCS
qgsdelimitedtextplugin.cpp
qgsdelimitedtextplugingui.cpp
)

SET (DLTEXT_UIS qgsdelimitedtextpluginguibase.ui)
SET (DLTEXT_SRCS qgsdelimitedtextplugin.cpp)

SET (DLTEXT_MOC_HDRS
qgsdelimitedtextplugin.h
qgsdelimitedtextplugingui.h
)
SET (DLTEXT_MOC_HDRS qgsdelimitedtextplugin.h)

SET (DLTEXT_RCCS delimited_text.qrc)

@@ -25,13 +17,14 @@ QT4_WRAP_CPP (DLTEXT_MOC_SRCS ${DLTEXT_MOC_HDRS})

QT4_ADD_RESOURCES(DLTEXT_RCC_SRCS ${DLTEXT_RCCS})

ADD_LIBRARY (delimitedtextplugin MODULE ${DLTEXT_SRCS} ${DLTEXT_MOC_SRCS} ${DLTEXT_RCC_SRCS} ${DLTEXT_UIS_H})
ADD_LIBRARY (delimitedtextplugin MODULE ${DLTEXT_SRCS} ${DLTEXT_MOC_SRCS} ${DLTEXT_RCC_SRCS})

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/raster ../../core/renderer ../../core/symbology
../../gui
..
../../providers/delimitedtext/delimitedtext
)

TARGET_LINK_LIBRARIES(delimitedtextplugin
@@ -25,15 +25,14 @@
#include "qgisgui.h"
#include "qgsapplication.h"
#include "qgsmaplayer.h"
#include "qgsproviderregistry.h"
#include "qgsdelimitedtextplugin.h"

#include <QMenu>
#include <QAction>
#include <QFile>
#include <QToolBar>

//the gui subclass
#include "qgsdelimitedtextplugingui.h"
#include <QMessageBox>

static const QString pluginVersion = QObject::tr( "Version 0.2" );
static const QString description_ = QObject::tr( "Loads and displays delimited text files containing x,y coordinates" );
@@ -118,22 +117,24 @@ void QgsDelimitedTextPlugin::initGui()
// Slot called when the buffer menu item is activated
void QgsDelimitedTextPlugin::run()
{
QgsDelimitedTextPluginGui *myQgsDelimitedTextPluginGui =
new QgsDelimitedTextPluginGui( qGisInterface,
qGisInterface->mainWindow(), QgisGui::ModalDialogFlags );
myQgsDelimitedTextPluginGui->setAttribute( Qt::WA_DeleteOnClose );
// show the DelimitedText dialog
QDialog *dlg = dynamic_cast<QDialog*>( QgsProviderRegistry::instance()->selectWidget( QString( "delimitedtext" ), qGisInterface->mainWindow() ) );
if ( !dlg )
{
QMessageBox::warning( qGisInterface->mainWindow(), tr( "Delimited Text" ), tr( "Cannot get Delimited Text select dialog from provider." ) );
return;
}
//listen for when the layer has been made so we can draw it
connect( myQgsDelimitedTextPluginGui,
SIGNAL( drawVectorLayer( QString, QString, QString ) ),
this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
myQgsDelimitedTextPluginGui->exec();
connect( dlg, SIGNAL( addVectorLayer( QString, QString, QString ) ),
this, SLOT( addVectorLayer( QString, QString, QString ) ) );

dlg->exec();
delete dlg;
}

//!draw a vector layer in the qui - intended to respond to signal
//sent by diolog when it as finished creating a layer
////needs to be given vectorLayerPath, baseName,
//providerKey ("ogr" or "postgres");
void QgsDelimitedTextPlugin::drawVectorLayer( QString thePathNameQString,
//!add a vector layer - intended to respond to signal
//sent by dialog when it as finished
void QgsDelimitedTextPlugin::addVectorLayer( QString thePathNameQString,
QString theBaseNameQString, QString theProviderQString )
{
qGisInterface->addVectorLayer( thePathNameQString,
@@ -65,8 +65,8 @@ class QgsDelimitedTextPlugin: public QObject, public QgisPlugin, private Ui::Qgs
virtual void initGui();
//! Show the dialog box
void run();
//! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
void drawVectorLayer( QString, QString, QString );
//! Add a vector layer given vectorLayerPath, baseName, providerKey (i.e. delimitedtext)
void addVectorLayer( QString, QString, QString );
//! unload the plugin
void unload();
//! show the help document
@@ -2,18 +2,24 @@
########################################################
# Files

SET (DTEXT_SRCS qgsdelimitedtextprovider.cpp)
SET (DTEXT_SRCS
qgsdelimitedtextprovider.cpp
qgsdelimitedtextsourceselect.cpp
)

SET (DTEXT_MOC_HDRS qgsdelimitedtextprovider.h)
SET (DTEXT_MOC_HDRS
qgsdelimitedtextprovider.h
qgsdelimitedtextsourceselect.h
)

########################################################
# Build

INCLUDE_DIRECTORIES(
.
../../core
${GDAL_INCLUDE_DIR}
../../gui
${GEOS_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../../ui
)

QT4_WRAP_CPP(DTEXT_MOC_SRCS ${DTEXT_MOC_HDRS})
@@ -37,6 +37,8 @@
#include "qgsrectangle.h"
#include "qgis.h"

#include "qgsdelimitedtextsourceselect.h"

static const QString TEXT_PROVIDER_KEY = "delimitedtext";
static const QString TEXT_PROVIDER_DESCRIPTION = "Delimited text data provider";

@@ -66,19 +68,19 @@ QString QgsDelimitedTextProvider::readLine( QTextStream *stream )
return buffer;
}

QStringList QgsDelimitedTextProvider::splitLine( QString line )
QStringList QgsDelimitedTextProvider::splitLine( QString line, QString delimiterType, QString delimiter )
{
QgsDebugMsgLevel( "Attempting to split the input line: " + line + " using delimiter " + mDelimiter, 3 );
QgsDebugMsgLevel( "Attempting to split the input line: " + line + " using delimiter " + delimiter, 3 );

QStringList parts;
if ( mDelimiterType == "regexp" )
parts = line.split( mDelimiterRegexp );
if ( delimiterType == "regexp" )
parts = line.split( QRegExp( delimiter ) );
else
parts = line.split( mDelimiter );
parts = line.split( delimiter );

QgsDebugMsgLevel( "Split line into " + QString::number( parts.size() ) + " parts", 3 );

if ( mDelimiterType == "plain" )
if ( delimiterType == "plain" )
{
QChar delim;
int i = 0, first = parts.size();
@@ -106,7 +108,7 @@ QStringList QgsDelimitedTextProvider::splitLine( QString line )
i--;
}

parts.insert( first, values.join( mDelimiter ) );
parts.insert( first, values.join( delimiter ) );
}

first = -1;
@@ -130,7 +132,6 @@ QStringList QgsDelimitedTextProvider::splitLine( QString line )
QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
: QgsVectorDataProvider( uri )
, mDelimiter( "," )
, mDelimiterRegexp()
, mDelimiterType( "plain" )
, mFieldCount( 0 )
, mXFieldIndex( -1 )
@@ -183,9 +184,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
QgsDebugMsg( "skipLines is: " + QString::number( mSkipLines ) );

// if delimiter contains some special characters, convert them
if ( mDelimiterType == "regexp" )
mDelimiterRegexp = QRegExp( mDelimiter );
else
if ( mDelimiterType != "regexp" )
mDelimiter.replace( "\\t", "\t" ); // replace "\t" with a real tabulator

// Set the selection rectangle to null
@@ -771,3 +770,8 @@ QGISEXTERN bool isProvider()
{
return true;
}

QGISEXTERN QgsDelimitedTextSourceSelect *selectWidget( QWidget *parent, Qt::WFlags fl )
{
return new QgsDelimitedTextSourceSelect( parent, fl );
}
@@ -175,6 +175,10 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
*/
bool boundsCheck( QgsGeometry *geom );


static QString readLine( QTextStream *stream );
static QStringList splitLine( QString line, QString delimiterType, QString delimiter );

private:

//! Fields
@@ -246,6 +250,5 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider

QGis::WkbType mWkbType;

QString readLine( QTextStream *stream );
QStringList splitLine( QString line );
QStringList splitLine( QString line ) { return splitLine( line, mDelimiterType, mDelimiter ); }
};

0 comments on commit beb70d3

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