Skip to content

Commit 44d8db9

Browse files
committedNov 7, 2017
editable and lable on top + fixes
in attribute form properties: editable and lable on top config to general fix: in case that somebody deletes a field on sourcedata and then wants to change config on it in attribute - it's now disabled (but not updated) fix: if adding new attribute after adding a virtual one, the display of the list was wrong (value of virtual in non-virtual row) - now it reloads the table correctly
1 parent 3c9cef3 commit 44d8db9

File tree

4 files changed

+55
-85
lines changed

4 files changed

+55
-85
lines changed
 

‎src/app/qgsattributesformproperties.cpp

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ void QgsAttributesFormProperties::initInitPython()
215215

216216
void QgsAttributesFormProperties::loadAttributeTypeDialog()
217217
{
218-
QTreeWidgetItem *currentItem = mAvailableWidgetsTree->currentItem();
219-
220-
if ( !currentItem )
218+
//check if item or field with the items name for some reason not available anymore
219+
if ( !mAvailableWidgetsTree->currentItem() ||
220+
getFieldIndexByName( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
221221
mAttributeTypeDialog->setEnabled( false );
222222
else
223223
{
@@ -227,16 +227,13 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
227227

228228
mAttributeTypeDialog->setEnabled( true );
229229

230-
// AttributeTypeDialog
231-
230+
// AttributeTypeDialog delete and recreate
232231
mAttributeTypeFrame->layout()->removeWidget( mAttributeTypeDialog );
233232
delete mAttributeTypeDialog;
234-
235-
236-
//
237233
mAttributeTypeDialog = new QgsAttributeTypeDialog( mLayer, index, mAttributeTypeFrame );
234+
238235
mAttributeTypeDialog->setAlias( cfg.mAlias );
239-
mAttributeTypeDialog->setComment( mLayer->fields().at( index ).comment() );
236+
mAttributeTypeDialog->setComment( cfg.mComment );
240237
mAttributeTypeDialog->setFieldEditable( cfg.mEditable );
241238
mAttributeTypeDialog->setLabelOnTop( cfg.mLabelOnTop );
242239
mAttributeTypeDialog->setNotNull( cfg.mConstraints & QgsFieldConstraints::ConstraintNotNull );
@@ -393,24 +390,6 @@ void QgsAttributesFormProperties::storeAttributeRelationEdit()
393390
}
394391
}
395392

396-
QgsAttributesFormProperties::FieldConfig QgsAttributesFormProperties::configForChild( int index )
397-
{
398-
QString fieldName = mLayer->fields().at( index ).name();
399-
400-
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
401-
while ( *itemIt )
402-
{
403-
QTreeWidgetItem *item = *itemIt;
404-
if ( item->data( 0, FieldNameRole ).toString() == fieldName )
405-
return item->data( 0, FieldConfigRole ).value<FieldConfig>();
406-
++itemIt;
407-
}
408-
409-
// Should never get here
410-
Q_ASSERT( false );
411-
return FieldConfig();
412-
}
413-
414393
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationName )
415394
{
416395
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
@@ -646,6 +625,18 @@ void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
646625
mEditFormLineEdit->setText( uifilename );
647626
}
648627

628+
int QgsAttributesFormProperties::getFieldIndexByName( const QString &name )
629+
{
630+
for ( int idx = 0; idx < mLayer->fields().size(); idx++ )
631+
{
632+
//only save the files that are still existing in fields
633+
if ( mLayer->fields().at( idx ).name() == name )
634+
return idx;
635+
}
636+
637+
return -1;
638+
}
639+
649640
void QgsAttributesFormProperties::apply()
650641
{
651642

@@ -656,15 +647,15 @@ void QgsAttributesFormProperties::apply()
656647

657648
QTreeWidgetItem *fieldContainer = mAvailableWidgetsTree->invisibleRootItem()->child( 0 );
658649

659-
int idx;
660-
661650
for ( int i = 0; i < fieldContainer->childCount(); i++ )
662651
{
663652
QTreeWidgetItem *fieldItem = fieldContainer->child( i );
664-
idx = fieldContainer->indexOfChild( fieldItem );
653+
FieldConfig cfg = fieldItem->data( 0, FieldConfigRole ).value<FieldConfig>();
654+
655+
int idx = getFieldIndexByName( fieldItem->data( 0, FieldNameRole ).toString() );
665656

666-
QString name = mLayer->fields().at( idx ).name();
667-
FieldConfig cfg = configForChild( idx );
657+
//continue in case field does not exist anymore
658+
if ( idx < 0 ) continue;
668659

669660
editFormConfig.setReadOnly( idx, !cfg.mEditable );
670661
editFormConfig.setLabelOnTop( idx, cfg.mLabelOnTop );
@@ -697,7 +688,6 @@ void QgsAttributesFormProperties::apply()
697688
}
698689

699690
mLayer->setFieldAlias( idx, cfg.mAlias );
700-
//wo?? ( idx, cfg.mComment );
701691
}
702692

703693
// tabs and groups
@@ -736,28 +726,6 @@ void QgsAttributesFormProperties::apply()
736726
editFormConfig.setWidgetConfig( itemData.name(), cfg );
737727
}
738728

739-
/*
740-
741-
for ( int i = 0; i < mRelationsList->rowCount(); ++i )
742-
{
743-
QVariantMap cfg;
744-
745-
QComboBox *cb = qobject_cast<QComboBox *>( mRelationsList->cellWidget( i, RelNmCol ) );
746-
QVariant otherRelation = cb->currentData();
747-
748-
if ( otherRelation.isValid() )
749-
{
750-
cfg[QStringLiteral( "nm-rel" )] = otherRelation.toString();
751-
}
752-
753-
DesignerTreeItemData itemData = mRelationsList->item( i, RelNameCol )->data( DesignerTreeRole ).value<DesignerTreeItemData>();
754-
755-
QString relationName = itemData.name();
756-
757-
editFormConfig.setWidgetConfig( relationName, cfg );
758-
}
759-
*/
760-
761729
mLayer->setEditFormConfig( editFormConfig );
762730
}
763731

@@ -780,6 +748,7 @@ QgsAttributesFormProperties::FieldConfig::FieldConfig( QgsVectorLayer *layer, in
780748
: mButton( nullptr )
781749
{
782750
mAlias = layer->fields().at( idx ).alias();
751+
mComment = layer->fields().at( idx ).comment();
783752
mEditable = !layer->editFormConfig().readOnly( idx );
784753
mEditableEnabled = layer->fields().fieldOrigin( idx ) != QgsFields::OriginJoin
785754
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;

‎src/app/qgsattributesformproperties.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
195195
protected:
196196
void updateButtons();
197197

198-
FieldConfig configForChild( int index );
199-
void setConfigForChild( int index, const FieldConfig &cfg );
200-
201198
RelationConfig configForRelation( const QString &relationName );
202199

203200
//QList<QgsRelation> mRelations;
@@ -216,6 +213,8 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
216213
void loadAttributeRelationEdit();
217214
void storeAttributeRelationEdit( );
218215

216+
int getFieldIndexByName( const QString &name );
217+
219218
QgsEditFormConfig::PythonInitCodeSource mInitCodeSource;
220219
QString mInitFunction;
221220
QString mInitFilePath;

‎src/app/qgssourcefieldsproperties.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ bool QgsSourceFieldsProperties::addAttribute( const QgsField &field )
281281
void QgsSourceFieldsProperties::apply()
282282
{
283283
// Disabled: we deal with the configuration in the new tabs
284+
284285
QSet<QString> excludeAttributesWMS, excludeAttributesWFS;
285286

286287
for ( int i = 0; i < mFieldsList->rowCount(); i++ )
@@ -314,7 +315,7 @@ void QgsSourceFieldsProperties::addAttributeClicked()
314315
if ( dialog.exec() == QDialog::Accepted )
315316
{
316317
addAttribute( dialog.field() );
317-
318+
loadRows();
318319
}
319320
}
320321

@@ -358,7 +359,10 @@ void QgsSourceFieldsProperties::calculateFieldClicked()
358359
}
359360

360361
QgsFieldCalculator calc( mLayer, this );
361-
calc.exec();
362+
if ( calc.exec() == QDialog::Accepted )
363+
{
364+
loadRows();
365+
}
362366
}
363367

364368
void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )

‎src/ui/qgsattributetypeedit.ui

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,37 @@
3434
</property>
3535
</widget>
3636
</item>
37-
<item row="0" column="1">
37+
<item row="0" column="2">
3838
<widget class="QLineEdit" name="leAlias">
3939
<property name="text">
4040
<string/>
4141
</property>
4242
</widget>
4343
</item>
44-
<item row="1" column="1">
44+
<item row="1" column="2">
4545
<widget class="QLabel" name="laComment">
4646
<property name="text">
47-
<string> </string>
47+
<string/>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="2" column="0">
52+
<widget class="QCheckBox" name="isFieldEditableCheckBox">
53+
<property name="text">
54+
<string>Editable</string>
55+
</property>
56+
<property name="checked">
57+
<bool>true</bool>
58+
</property>
59+
</widget>
60+
</item>
61+
<item row="2" column="2">
62+
<widget class="QCheckBox" name="labelOnTopCheckBox">
63+
<property name="text">
64+
<string>Label on top</string>
65+
</property>
66+
<property name="checked">
67+
<bool>false</bool>
4868
</property>
4969
</widget>
5070
</item>
@@ -158,26 +178,6 @@
158178
</item>
159179
<item>
160180
<layout class="QGridLayout" name="gridLayout_4">
161-
<item row="0" column="0">
162-
<widget class="QCheckBox" name="isFieldEditableCheckBox">
163-
<property name="text">
164-
<string>Editable</string>
165-
</property>
166-
<property name="checked">
167-
<bool>true</bool>
168-
</property>
169-
</widget>
170-
</item>
171-
<item row="1" column="0">
172-
<widget class="QCheckBox" name="labelOnTopCheckBox">
173-
<property name="text">
174-
<string>Label on top</string>
175-
</property>
176-
<property name="checked">
177-
<bool>false</bool>
178-
</property>
179-
</widget>
180-
</item>
181181
<item row="2" column="0">
182182
<widget class="QGroupBox" name="groupBox_2">
183183
<property name="title">
@@ -250,8 +250,6 @@
250250
</customwidget>
251251
</customwidgets>
252252
<tabstops>
253-
<tabstop>isFieldEditableCheckBox</tabstop>
254-
<tabstop>labelOnTopCheckBox</tabstop>
255253
<tabstop>mExpressionWidget</tabstop>
256254
<tabstop>groupBox</tabstop>
257255
<tabstop>notNullCheckBox</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.