Skip to content
Permalink
Browse files

Provider source widgets can be used for vector layers

  • Loading branch information
nyalldawson committed Jan 12, 2021
1 parent b44e94d commit 99ba9b21185248fc82df6e5fa7717cf299f1539f
@@ -68,6 +68,8 @@
#include "qgsexpressioncontextutils.h"
#include "qgsmaskingwidget.h"
#include "qgsvectorlayertemporalpropertieswidget.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsprovidersourcewidget.h"

#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"
@@ -143,6 +145,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
}
connect( mActionSaveStyle, &QAction::triggered, this, &QgsVectorLayerProperties::saveStyleAs );

mSourceGroupBox->hide();

menuStyle->addSeparator();
menuStyle->addAction( tr( "Save as Default" ), this, &QgsVectorLayerProperties::saveDefaultStyle_clicked );
menuStyle->addAction( tr( "Restore Default" ), this, &QgsVectorLayerProperties::loadDefaultStyle_clicked );
@@ -490,6 +494,27 @@ void QgsVectorLayerProperties::insertFieldOrExpression()
// in raster props, this method is called sync()
void QgsVectorLayerProperties::syncToLayer()
{
if ( !mSourceWidget )
{
mSourceWidget = QgsGui::sourceWidgetProviderRegistry()->createWidget( mLayer );
if ( mSourceWidget )
{
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget( mSourceWidget );
mSourceGroupBox->setLayout( layout );
mSourceGroupBox->show();

connect( mSourceWidget, &QgsProviderSourceWidget::validChanged, this, [ = ]( bool isValid )
{
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
} );
}
}

if ( mSourceWidget )
mSourceWidget->setSourceUri( mLayer->source() );

// populate the general information
mLayerOrigNameLineEdit->setText( mLayer->name() );
txtDisplayName->setText( mLayer->name() );
@@ -605,6 +630,15 @@ void QgsVectorLayerProperties::syncToLayer()

void QgsVectorLayerProperties::apply()
{
if ( mSourceWidget )
{
const QString newSource = mSourceWidget->sourceUri();
if ( newSource != mLayer->source() )
{
mLayer->setDataSource( newSource, mLayer->name(), mLayer->providerType(), QgsDataProvider::ProviderOptions() );
}
}

if ( labelingDialog )
{
labelingDialog->writeSettingsToLayer();
@@ -50,6 +50,7 @@ class QgsMapLayerComboBox;
class QgsDoubleSpinBox;
class QgsMaskingWidget;
class QgsVectorLayerTemporalPropertiesWidget;
class QgsProviderSourceWidget;

class GUI_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private Ui::QgsVectorLayerPropertiesBase, private QgsExpressionContextGenerator
{
@@ -246,6 +247,8 @@ class GUI_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

QgsVectorLayerTemporalPropertiesWidget *mTemporalWidget = nullptr;

QgsProviderSourceWidget *mSourceWidget = nullptr;

private slots:
void openPanel( QgsPanelWidget *panel );

@@ -603,6 +603,13 @@ border-radius: 2px;</string>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mSourceGroupBox">
<property name="title">
<string>Layer Source</string>
</property>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mGeomGroupBox">
<property name="focusPolicy">
@@ -2559,6 +2566,11 @@ border-radius: 2px;</string>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
@@ -2570,11 +2582,6 @@ border-radius: 2px;</string>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>

0 comments on commit 99ba9b2

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