Skip to content

Commit

Permalink
[FEATURE] Add 'Suppress attribute form pop-up after feature creation'…
Browse files Browse the repository at this point in the history
… option to vector layers; overrides application-wide option
  • Loading branch information
dakcarto committed Sep 6, 2013
1 parent 9ebf1fe commit 3b6d4ef
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 88 deletions.
14 changes: 13 additions & 1 deletion src/app/qgsfeatureaction.cpp
Expand Up @@ -2,7 +2,7 @@
qgsfeatureaction.cpp - description
-------------------
begin : 2010-09-20
copyright : (C) 2010 by Jürgen E. Fischer
copyright : (C) 2010 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/

Expand Down Expand Up @@ -171,6 +171,18 @@ bool QgsFeatureAction::addFeature()

// show the dialog to enter attribute values
bool isDisabledAttributeValuesDlg = settings.value( "/qgis/digitizing/disable_enter_attribute_values_dialog", false ).toBool();
// override application-wide setting with any layer setting
switch ( mLayer->featureFormSuppress() )
{
case QgsVectorLayer::SuppressOn:
isDisabledAttributeValuesDlg = true;
break;
case QgsVectorLayer::SuppressOff:
isDisabledAttributeValuesDlg = false;
break;
case QgsVectorLayer::SuppressDefault:
break;
}
if ( isDisabledAttributeValuesDlg )
{
res = mLayer->addFeature( mFeature );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -219,6 +219,7 @@ void QgsFieldsProperties::init()
loadRows();

mEditorLayoutComboBox->setCurrentIndex( mLayer->editorLayout() );
mFormSuppressCmbBx->setCurrentIndex( mLayer->featureFormSuppress() );

loadAttributeEditorTree();
}
Expand Down Expand Up @@ -918,6 +919,7 @@ void QgsFieldsProperties::apply()
mLayer->setEditorLayout(( QgsVectorLayer::EditorLayout )mEditorLayoutComboBox->currentIndex() );
mLayer->setEditForm( leEditForm->text() );
mLayer->setEditFormInit( leEditFormInit->text() );
mLayer->setFeatureFormSuppress(( QgsVectorLayer::FeatureFormSuppress )mFormSuppressCmbBx->currentIndex() );

mLayer->setExcludeAttributesWMS( excludeAttributesWMS );
mLayer->setExcludeAttributesWFS( excludeAttributesWFS );
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -125,6 +125,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mFeatureBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal feature blending
, mLayerTransparency( 0 )
, mVertexMarkerOnlyForSelection( false )
, mFeatureFormSuppress( SuppressDefault )
, mCache( new QgsGeometryCache( this ) )
, mEditBuffer( 0 )
, mJoinBuffer( 0 )
Expand Down Expand Up @@ -1982,6 +1983,17 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mEditFormInit = editFormInitNode.toElement().text();
}

QDomNode fFSuppNode = node.namedItem( "featformsuppress" );
if ( fFSuppNode.isNull() )
{
mFeatureFormSuppress = SuppressDefault;
}
else
{
QDomElement e = fFSuppNode.toElement();
mFeatureFormSuppress = ( QgsVectorLayer::FeatureFormSuppress )e.text().toInt();
}

QDomNode annotationFormNode = node.namedItem( "annotationform" );
if ( !annotationFormNode.isNull() )
{
Expand Down Expand Up @@ -2290,6 +2302,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
efiField.appendChild( efiText );
node.appendChild( efiField );

QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
QDomText fFSuppText = doc.createTextNode( QString::number( featureFormSuppress() ) );
fFSuppElem.appendChild( fFSuppText );
node.appendChild( fFSuppElem );

QDomElement afField = doc.createElement( "annotationform" );
QDomText afText = doc.createTextNode( QgsProject::instance()->writePath( mAnnotationForm ) );
afField.appendChild( afText );
Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -446,6 +446,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
Color, /**< color @note added in 1.9 */
};

/** Types of feature form suppression after feature creation
* @note added in 2.1 */
enum FeatureFormSuppress
{
SuppressDefault = 0, // use the application-wide setting
SuppressOn = 1,
SuppressOff = 2
};

struct RangeData
{
RangeData() {}
Expand Down Expand Up @@ -1112,6 +1121,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** set edit form (added in 1.4) */
void setEditForm( QString ui );

/** Type of feature form pop-up suppression after feature creation (overrides app setting)
* @note added in 2.1 */
QgsVectorLayer::FeatureFormSuppress featureFormSuppress() const { return mFeatureFormSuppress; }

/** Set type of feature form pop-up suppression after feature creation (overrides app setting)
* @note added in 2.1 */
void setFeatureFormSuppress( QgsVectorLayer::FeatureFormSuppress s ) { mFeatureFormSuppress = s; }

/** get annotation form (added in 1.5)*/
QString annotationForm() const { return mAnnotationForm; }

Expand Down Expand Up @@ -1539,6 +1556,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
EditorLayout mEditorLayout;

QString mEditForm, mEditFormInit;

/** Type of feature form suppression after feature creation
* @note added in 2.1 */
QgsVectorLayer::FeatureFormSuppress mFeatureFormSuppress;

//annotation form for this layer
QString mAnnotationForm;

Expand Down
223 changes: 137 additions & 86 deletions src/ui/qgsfieldspropertiesbase.ui
Expand Up @@ -6,11 +6,45 @@
<rect>
<x>0</x>
<y>0</y>
<width>782</width>
<height>663</height>
<width>871</width>
<height>712</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="5">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>QGIS forms can have a Python function that is called when the form is opened.
Use this function to add extra logic to your forms.

An example is (in module MyForms.py):

def open(dialog, layer, feature):
geom = feature.geometry()
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)

Reference in Python Init Function like so: MyForms.open

MyForms.py must live on PYTHONPATH, .qgis/python, or inside the project folder.</string>
</property>
<property name="text">
<string>Python Init function</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>19</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="mAddAttributeButton">
<property name="sizePolicy">
Expand All @@ -34,52 +68,32 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="mCalculateFieldButton">
<property name="toolTip">
<string>Field calculator</string>
</property>
<property name="whatsThis">
<string>Click to toggle table editing</string>
</property>
<item row="1" column="6">
<widget class="QLineEdit" name="leEditFormInit"/>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label_2">
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
<string>Attribute editor layout:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="mDeleteAttributeButton">
<item row="0" column="2">
<widget class="QToolButton" name="mToggleEditingButton">
<property name="toolTip">
<string>Delete column</string>
<string>Toggle editing mode</string>
</property>
<property name="whatsThis">
<string>Click to toggle table editing</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>.designer/xpm/delete_attribute.png</normaloff>.designer/xpm/delete_attribute.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>19</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="6">
<widget class="QComboBox" name="mEditorLayoutComboBox">
<property name="sizePolicy">
Expand All @@ -105,53 +119,6 @@
</item>
</widget>
</item>
<item row="1" column="5">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>QGIS forms can have a Python function that is called when the form is opened.
Use this function to add extra logic to your forms.

An example is (in module MyForms.py):

def open(dialog, layer, feature):
geom = feature.geometry()
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)

Reference in Python Init Function like so: MyForms.open

MyForms.py must live on PYTHONPATH, .qgis/python, or inside the project folder.</string>
</property>
<property name="text">
<string>Python Init function</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="mToggleEditingButton">
<property name="toolTip">
<string>Toggle editing mode</string>
</property>
<property name="whatsThis">
<string>Click to toggle table editing</string>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QLineEdit" name="leEditFormInit"/>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Attribute editor layout:</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="7">
<widget class="QSplitter" name="mSplitter">
<property name="orientation">
Expand Down Expand Up @@ -230,9 +197,6 @@ MyForms.py must live on PYTHONPATH, .qgis/python, or inside the project folder.<
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
Expand Down Expand Up @@ -342,6 +306,93 @@ MyForms.py must live on PYTHONPATH, .qgis/python, or inside the project folder.<
</widget>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="mCalculateFieldButton">
<property name="toolTip">
<string>Field calculator</string>
</property>
<property name="whatsThis">
<string>Click to toggle table editing</string>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="mDeleteAttributeButton">
<property name="toolTip">
<string>Delete column</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>.designer/xpm/delete_attribute.png</normaloff>.designer/xpm/delete_attribute.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mFormSuppressLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Suppress attribute form pop-up after feature creation</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mFormSuppressCmbBx">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>On</string>
</property>
</item>
<item>
<property name="text">
<string>Off</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
Expand Down

0 comments on commit 3b6d4ef

Please sign in to comment.