Skip to content
Permalink
Browse files

[addlayerbutton] Added delimited text layers

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent de5996c commit 6c66738d129972486b6ccfe5d6bb17fd0644ee11
@@ -52,6 +52,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
ui->mOptionsStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mOptionsListWidget );
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
ogrItem->setToolTip( tr( "Add Vector layer" ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );

// Add data provider dialogs
@@ -98,6 +99,13 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "arcgisfeatureserver" ) ); } );
}

dlg = providerDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) );

if ( dlg )
{
connect( dlg, SIGNAL( addVectorLayer( QString, QString, QString ) ), this, SLOT( vectorLayerAdded( QString, QString, QString ) ) );
}

}

QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
@@ -138,8 +146,9 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
else
{
ui->mOptionsStackedWidget->addWidget( dlg );
QListWidgetItem *wmsItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
wmsItem->setIcon( QgsApplication::getThemeIcon( icon ) );
QListWidgetItem *layerItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
layerItem->setToolTip( tr( "Add %1 layer" ).arg( providerName ) );
layerItem->setIcon( QgsApplication::getThemeIcon( icon ) );
return dlg;
}
}
@@ -20,6 +20,7 @@
#include "qgsdelimitedtextprovider.h"
#include "qgsdelimitedtextfile.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"

#include <QButtonGroup>
#include <QFile>
@@ -33,24 +34,25 @@

const int MAX_SAMPLE_LENGTH = 200;

QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embedded )
QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl )
, mFile( new QgsDelimitedTextFile() )
, mExampleRowCount( 20 )
, mBadRowCount( 0 )
, mPluginKey( QStringLiteral( "/Plugin-DelimitedText" ) )
, mLastFileType( QLatin1String( "" ) )
, mWidgetMode( widgetMode )
{

setupUi( this );

QgsSettings settings;
restoreGeometry( settings.value( mPluginKey + "/geometry" ).toByteArray() );

if ( embedded )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->button( QDialogButtonBox::Cancel )->hide();
buttonBox->button( QDialogButtonBox::Ok )->hide();
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Add" ) );
}

bgFileFormat = new QButtonGroup( this );
@@ -198,8 +200,10 @@ void QgsDelimitedTextSourceSelect::on_buttonBox_accepted()

// add the layer to the map
emit addVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text(), QStringLiteral( "delimitedtext" ) );

accept();
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
accept();
}
}

void QgsDelimitedTextSourceSelect::on_buttonBox_rejected()
@@ -18,6 +18,7 @@
#include <QTextStream>
#include "qgshelp.h"
#include "qgsguiutils.h"
#include "qgsproviderregistry.h"

class QButtonGroup;
class QgisInterface;
@@ -31,7 +32,7 @@ class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTex
Q_OBJECT

public:
QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, bool embedded = false );
QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
~QgsDelimitedTextSourceSelect();

QStringList splitLine( QString line );
@@ -56,6 +57,7 @@ class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTex
QString mLastFileType;
QButtonGroup *bgFileFormat = nullptr;
QButtonGroup *bgGeomType = nullptr;
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;

private slots:
void on_buttonBox_accepted();

0 comments on commit 6c66738

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