Skip to content

Commit

Permalink
[addlayerbutton] Added delimited text layers
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent de5996c commit 6c66738
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/app/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgsdelimitedtextprovider.h"
#include "qgsdelimitedtextfile.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"

#include <QButtonGroup>
#include <QFile>
Expand All @@ -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 );
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QTextStream>
#include "qgshelp.h"
#include "qgsguiutils.h"
#include "qgsproviderregistry.h"

class QButtonGroup;
class QgisInterface;
Expand All @@ -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 );
Expand All @@ -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();
Expand Down

0 comments on commit 6c66738

Please sign in to comment.