28 #include <QStandardItemModel>
29 #include <QPushButton>
32 : QDialog( parent, f )
36 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
38 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#joins-properties" ) );
46 alreadyJoinedLayers.append( layer );
48 mTargetFieldComboBox->setLayer( mLayer );
50 mDynamicFormCheckBox->setToolTip( tr(
"This option allows values of the joined fields to be automatically reloaded when the \"Target Field\" is changed" ) );
52 mEditableJoinLayer->setToolTip( tr(
"This option allows values of the joined layers to be editable if they're themselves editable" ) );
53 mUpsertOnEditCheckBox->setToolTip( tr(
"Automatically adds a matching row to the joined table, but if one already exists then update that matching row instead" ) );
54 mDeleteCascadeCheckBox->setToolTip( tr(
"Automatically delete the corresponding feature of the linked layer if one exists" ) );
57 mJoinLayerComboBox->setExceptedLayerList( alreadyJoinedLayers );
61 mCacheInMemoryCheckBox->setChecked(
true );
62 mCacheEnabled = mCacheInMemoryCheckBox->isChecked();
64 QgsMapLayer *joinLayer = mJoinLayerComboBox->currentLayer();
65 if ( joinLayer && joinLayer->
isValid() )
67 mJoinFieldComboBox->setLayer( joinLayer );
68 joinedLayerChanged( joinLayer );
74 connect( mEditableJoinLayer, &QGroupBox::toggled,
this, &QgsJoinDialog::editableJoinLayerChanged );
76 checkDefinitionValid();
95 mUseCustomPrefix->setChecked(
false );
99 mUseCustomPrefix->setChecked(
true );
104 mUseJoinFieldsSubset->setChecked( lst && !lst->isEmpty() );
105 QAbstractItemModel *model = mJoinFieldsSubsetView->model();
108 for (
int i = 0; i < model->rowCount(); ++i )
110 const QModelIndex index = model->index( i, 0 );
111 if ( lst && lst->contains( model->data( index, Qt::DisplayRole ).toString() ) )
113 model->setData( index, Qt::Checked, Qt::CheckStateRole );
117 model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
122 editableJoinLayerChanged();
128 info.
setJoinLayer( qobject_cast<QgsVectorLayer *>( mJoinLayerComboBox->currentLayer() ) );
134 info.
setEditable( mEditableJoinLayer->isChecked() );
141 if ( mUseCustomPrefix->isChecked() )
146 if ( mUseJoinFieldsSubset->isChecked() )
149 QAbstractItemModel *model = mJoinFieldsSubsetView->model();
152 for (
int i = 0; i < model->rowCount(); ++i )
154 const QModelIndex index = model->index( i, 0 );
155 if ( model->data( index, Qt::CheckStateRole ).toInt() == Qt::Checked )
156 lst << model->data( index ).toString();
167 return mCreateIndexCheckBox->isChecked();
170 void QgsJoinDialog::joinedLayerChanged(
QgsMapLayer *layer )
172 mJoinFieldComboBox->clear();
180 mUseJoinFieldsSubset->setChecked(
false );
181 QStandardItemModel *subsetModel =
new QStandardItemModel(
this );
185 QStandardItem *subsetItem =
new QStandardItem(
field.
name() );
186 subsetItem->setCheckable(
true );
188 subsetModel->appendRow( subsetItem );
190 mJoinFieldsSubsetView->setModel( subsetModel );
194 if ( canCreateAttrIndex )
196 mCreateIndexCheckBox->setEnabled(
true );
200 mCreateIndexCheckBox->setEnabled(
false );
201 mCreateIndexCheckBox->setChecked(
false );
204 if ( !mUseCustomPrefix->isChecked() )
206 mCustomPrefix->setText( layer->
name() +
'_' );
210 void QgsJoinDialog::checkDefinitionValid()
212 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mJoinLayerComboBox->currentIndex() != -1
213 && mJoinFieldComboBox->currentIndex() != -1
214 && mTargetFieldComboBox->currentIndex() != -1 );
217 void QgsJoinDialog::editableJoinLayerChanged()
219 if ( mEditableJoinLayer->isChecked() )
221 mCacheInMemoryCheckBox->setEnabled(
false );
222 mCacheInMemoryCheckBox->setToolTip( tr(
"Caching can not be enabled if editable join layer is enabled" ) );
223 mCacheEnabled = mCacheInMemoryCheckBox->isChecked();
224 mCacheInMemoryCheckBox->setChecked(
false );
228 mCacheInMemoryCheckBox->setEnabled(
true );
229 mCacheInMemoryCheckBox->setToolTip( QString() );
230 mCacheInMemoryCheckBox->setChecked( mCacheEnabled );