Skip to content
Permalink
Browse files

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
  • Loading branch information
signedav committed Nov 7, 2017
1 parent 3c9cef3 commit 44d8db9cdf1bfbbecd5441882c68fa1cde2f9c6f
@@ -215,9 +215,9 @@ void QgsAttributesFormProperties::initInitPython()

void QgsAttributesFormProperties::loadAttributeTypeDialog()
{
QTreeWidgetItem *currentItem = mAvailableWidgetsTree->currentItem();

if ( !currentItem )
//check if item or field with the items name for some reason not available anymore
if ( !mAvailableWidgetsTree->currentItem() ||
getFieldIndexByName( mAvailableWidgetsTree->currentItem()->data( 0, FieldNameRole ).toString() ) < 0 )
mAttributeTypeDialog->setEnabled( false );
else
{
@@ -227,16 +227,13 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()

mAttributeTypeDialog->setEnabled( true );

// AttributeTypeDialog

// AttributeTypeDialog delete and recreate
mAttributeTypeFrame->layout()->removeWidget( mAttributeTypeDialog );
delete mAttributeTypeDialog;


//
mAttributeTypeDialog = new QgsAttributeTypeDialog( mLayer, index, mAttributeTypeFrame );

mAttributeTypeDialog->setAlias( cfg.mAlias );
mAttributeTypeDialog->setComment( mLayer->fields().at( index ).comment() );
mAttributeTypeDialog->setComment( cfg.mComment );
mAttributeTypeDialog->setFieldEditable( cfg.mEditable );
mAttributeTypeDialog->setLabelOnTop( cfg.mLabelOnTop );
mAttributeTypeDialog->setNotNull( cfg.mConstraints & QgsFieldConstraints::ConstraintNotNull );
@@ -393,24 +390,6 @@ void QgsAttributesFormProperties::storeAttributeRelationEdit()
}
}

QgsAttributesFormProperties::FieldConfig QgsAttributesFormProperties::configForChild( int index )
{
QString fieldName = mLayer->fields().at( index ).name();

QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
while ( *itemIt )
{
QTreeWidgetItem *item = *itemIt;
if ( item->data( 0, FieldNameRole ).toString() == fieldName )
return item->data( 0, FieldConfigRole ).value<FieldConfig>();
++itemIt;
}

// Should never get here
Q_ASSERT( false );
return FieldConfig();
}

QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationName )
{
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
@@ -646,6 +625,18 @@ void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
mEditFormLineEdit->setText( uifilename );
}

int QgsAttributesFormProperties::getFieldIndexByName( const QString &name )
{
for ( int idx = 0; idx < mLayer->fields().size(); idx++ )
{
//only save the files that are still existing in fields
if ( mLayer->fields().at( idx ).name() == name )
return idx;
}

return -1;
}

void QgsAttributesFormProperties::apply()
{

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

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

int idx;

for ( int i = 0; i < fieldContainer->childCount(); i++ )
{
QTreeWidgetItem *fieldItem = fieldContainer->child( i );
idx = fieldContainer->indexOfChild( fieldItem );
FieldConfig cfg = fieldItem->data( 0, FieldConfigRole ).value<FieldConfig>();

int idx = getFieldIndexByName( fieldItem->data( 0, FieldNameRole ).toString() );

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

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

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

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

/*
for ( int i = 0; i < mRelationsList->rowCount(); ++i )
{
QVariantMap cfg;
QComboBox *cb = qobject_cast<QComboBox *>( mRelationsList->cellWidget( i, RelNmCol ) );
QVariant otherRelation = cb->currentData();
if ( otherRelation.isValid() )
{
cfg[QStringLiteral( "nm-rel" )] = otherRelation.toString();
}
DesignerTreeItemData itemData = mRelationsList->item( i, RelNameCol )->data( DesignerTreeRole ).value<DesignerTreeItemData>();
QString relationName = itemData.name();
editFormConfig.setWidgetConfig( relationName, cfg );
}
*/

mLayer->setEditFormConfig( editFormConfig );
}

@@ -780,6 +748,7 @@ QgsAttributesFormProperties::FieldConfig::FieldConfig( QgsVectorLayer *layer, in
: mButton( nullptr )
{
mAlias = layer->fields().at( idx ).alias();
mComment = layer->fields().at( idx ).comment();
mEditable = !layer->editFormConfig().readOnly( idx );
mEditableEnabled = layer->fields().fieldOrigin( idx ) != QgsFields::OriginJoin
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;
@@ -195,9 +195,6 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
protected:
void updateButtons();

FieldConfig configForChild( int index );
void setConfigForChild( int index, const FieldConfig &cfg );

RelationConfig configForRelation( const QString &relationName );

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

int getFieldIndexByName( const QString &name );

QgsEditFormConfig::PythonInitCodeSource mInitCodeSource;
QString mInitFunction;
QString mInitFilePath;
@@ -281,6 +281,7 @@ bool QgsSourceFieldsProperties::addAttribute( const QgsField &field )
void QgsSourceFieldsProperties::apply()
{
// Disabled: we deal with the configuration in the new tabs

QSet<QString> excludeAttributesWMS, excludeAttributesWFS;

for ( int i = 0; i < mFieldsList->rowCount(); i++ )
@@ -314,7 +315,7 @@ void QgsSourceFieldsProperties::addAttributeClicked()
if ( dialog.exec() == QDialog::Accepted )
{
addAttribute( dialog.field() );

loadRows();
}
}

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

QgsFieldCalculator calc( mLayer, this );
calc.exec();
if ( calc.exec() == QDialog::Accepted )
{
loadRows();
}
}

void QgsSourceFieldsProperties::attributesListCellChanged( int row, int column )
@@ -34,17 +34,37 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QLineEdit" name="leAlias">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="2">
<widget class="QLabel" name="laComment">
<property name="text">
<string> </string>
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="labelOnTopCheckBox">
<property name="text">
<string>Label on top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
@@ -158,26 +178,6 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="labelOnTopCheckBox">
<property name="text">
<string>Label on top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@@ -250,8 +250,6 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>isFieldEditableCheckBox</tabstop>
<tabstop>labelOnTopCheckBox</tabstop>
<tabstop>mExpressionWidget</tabstop>
<tabstop>groupBox</tabstop>
<tabstop>notNullCheckBox</tabstop>

0 comments on commit 44d8db9

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