Skip to content

Commit

Permalink
[FEATURE] add editable option for all edit types
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Mar 4, 2013
1 parent e2bf9c6 commit 9912d99
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/app/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
//show attribute alias if available
QString myFieldName = vl->attributeDisplayName( fldIdx );
int myFieldType = theFields[fldIdx].type();
bool isEditable = vl->fieldEditable( fldIdx );

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );
if ( !myWidget )
Expand Down Expand Up @@ -204,7 +205,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat

if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
myWidget->setEnabled( vl->isEditable() );
myWidget->setEnabled( vl->isEditable() && isEditable );
}

mypInnerLayout->addWidget( myWidget, index, 1 );
Expand Down Expand Up @@ -233,13 +234,15 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
if ( !myWidgets.size() )
continue;

bool isEditable = vl->fieldEditable( fldIdx );

for ( QList<QWidget *>::const_iterator itw = myWidgets.begin(); itw != myWidgets.end(); ++itw )
{
QgsAttributeEditor::createAttributeEditor( mDialog, *itw, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );

if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
( *itw )->setEnabled(( *itw )->isEnabled() && vl->isEditable() );
( *itw )->setEnabled(( *itw )->isEnabled() && vl->isEditable() && isEditable );
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ QMap<QString, QVariant> &QgsAttributeTypeDialog::valueMap()
return mValueMap;
}

bool QgsAttributeTypeDialog::fieldEditable()
{
return isFieldEditableCheckBox->isChecked();
}

void QgsAttributeTypeDialog::setFieldEditable(bool editable)
{
isFieldEditableCheckBox->setChecked( editable );
}

QPair<QString, QString> QgsAttributeTypeDialog::checkedState()
{
return QPair<QString, QString>( leCheckedState->text(), leUncheckedState->text() );
Expand Down Expand Up @@ -538,6 +548,8 @@ void QgsAttributeTypeDialog::setStackPage( int index )
void QgsAttributeTypeDialog::accept()
{
//store data to output variables
mFieldEditable = isFieldEditableCheckBox->isChecked();

switch ( selectionListWidget->currentRow() )
{
default:
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsattributetypedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
void setValueRelation( QgsVectorLayer::ValueRelationData valueRelationData );

/**
* Setter for checkbox for editable state of field
* @param bool editable
*/
void setFieldEditable( bool editable );

/**
* Getter for checked state after editing
* @return string representing the checked
Expand All @@ -105,6 +111,11 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
QgsVectorLayer::ValueRelationData valueRelationData();

/**
* Getter for checkbox for editable state of field
*/
bool fieldEditable();

private slots:
/**
* Slot to handle change of index in combobox to select correct page
Expand Down Expand Up @@ -160,6 +171,7 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
void updateMap( const QMap<QString, QVariant> &map );

bool mFieldEditable;

QMap<QString, QVariant> mValueMap;

Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,17 @@ void QgsFieldsProperties::attributeTypeDialog()

attributeTypeDialog.setIndex( index, mEditTypeMap.value( index, mLayer->editType( index ) ) );

attributeTypeDialog.setFieldEditable( mLayer->fieldEditable( index ) );

if ( !attributeTypeDialog.exec() )
return;

QgsVectorLayer::EditType editType = attributeTypeDialog.editType();

mEditTypeMap.insert( index, editType );

bool isFieldEditable = attributeTypeDialog.fieldEditable();
mFieldEditables.insert( index, isFieldEditable );

QString buttonText;
switch ( editType )
{
Expand Down Expand Up @@ -816,6 +820,8 @@ void QgsFieldsProperties::apply()
QgsVectorLayer::EditType editType = editTypeFromButtonText( pb->text() );
mLayer->setEditType( idx, editType );

mLayer->setFieldEditable( idx, mFieldEditables.value( idx, true ));

switch ( editType )
{
case QgsVectorLayer::ValueMap:
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsfieldsproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
QgsAttributesTree* mAttributesTree;
QgsAttributesList* mAttributesList;

QMap<int, bool> mFieldEditables;
QMap<int, QgsVectorLayer::ValueRelationData> mValueRelationData;
QMap<int, QMap<QString, QVariant> > mValueMaps;
QMap<int, QgsVectorLayer::RangeData> mRanges;
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,9 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
mEditTypes.insert( name, editType );

int editable = editTypeElement.attribute( "editable" , "1" ).toInt();
mFieldEditables.insert( name, editable == 1);

switch ( editType )
{
case ValueMap:
Expand Down Expand Up @@ -2933,6 +2936,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
QDomElement editTypeElement = doc.createElement( "edittype" );
editTypeElement.setAttribute( "name", it.key() );
editTypeElement.setAttribute( "type", it.value() );
editTypeElement.setAttribute( "editable", mFieldEditables[ it.key()]?1:0 );

switch (( EditType ) it.value() )
{
Expand Down Expand Up @@ -3895,6 +3899,22 @@ QgsVectorLayer::RangeData &QgsVectorLayer::range( int idx )
return mRanges[fieldName];
}

bool QgsVectorLayer::fieldEditable( int idx )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() && mEditTypes.contains( fields[idx].name() ) )
return mFieldEditables[ fields[idx].name() ];
else
return false;
}

void QgsVectorLayer::setFieldEditable( int idx, bool editable )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() && mEditTypes.contains( fields[idx].name() ) )
mFieldEditables[ fields[idx].name() ] = editable;
}

void QgsVectorLayer::addOverlay( QgsVectorOverlay* overlay )
{
mOverlays.push_back( overlay );
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
**/
ValueRelationData &valueRelation( int idx );

/**is edit widget editable
* @note added in 1.9
**/
bool fieldEditable( int idx );

/**set edit widget editable
* @note added in 1.9
**/
void setFieldEditable( int idx, bool editable );


/**Adds a new overlay to this class. QgsVectorLayer takes ownership of the object
@note this method was added in version 1.1
*/
Expand Down Expand Up @@ -1058,6 +1069,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
QStringList mCommitErrors;

QMap< QString, EditType > mEditTypes;
QMap< QString, bool> mFieldEditables;
QMap< QString, QMap<QString, QVariant> > mValueMaps;
QMap< QString, RangeData > mRanges;
QMap< QString, QPair<QString, QString> > mCheckedStates;
Expand Down
16 changes: 13 additions & 3 deletions src/ui/qgsattributetypeedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>615</width>
<height>421</height>
<width>620</width>
<height>418</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -23,7 +23,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>12</number>
<number>0</number>
</property>
<widget class="QWidget" name="lineEditPage">
<layout class="QVBoxLayout" name="verticalLayout_1">
Expand Down Expand Up @@ -753,6 +753,16 @@
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 9912d99

Please sign in to comment.