Skip to content

Commit

Permalink
[FEATURE] allow ordering of value relations by value and
Browse files Browse the repository at this point in the history
include value relations in sip bindings
  • Loading branch information
jef-n committed Jul 22, 2011
1 parent 5ea8aea commit 985ffbd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
30 changes: 25 additions & 5 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -59,12 +59,15 @@ public:
Classification,
EditRange,
SliderRange
CheckBox, /* @note added in 1.4 */
CheckBox, /* @note added in 1.4 */
FileName,
Enumeration, /* @note added in 1.4 */
Immutable, /* @note added in 1.4 */
Hidden, /* @note added in 1.4 */
TextEdit /* @note added in 1.4 */
Enumeration, /* @note added in 1.4 */
Immutable, /* @note added in 1.4 */
Hidden, /* @note added in 1.4 */
TextEdit /* @note added in 1.4 */
Calendar, /* calendar widget @added in 1.5 */
DialRange, /* dial range @added in 1.5 */
ValueRelation, /* value map from an table @added in 1.8 */
};

struct RangeData {
Expand All @@ -76,6 +79,18 @@ public:
QVariant mStep;
};

struct ValueRelationData
{
ValueRelationData();
ValueRelationData( QString layer, QString key, QString value, bool allowNull, bool orderByValue );

QString mLayer;
QString mKey;
QString mValue;
bool mAllowNull;
bool mOrderByValue;
};

/** Constructor */
QgsVectorLayer(QString baseName = 0, QString path = 0, QString providerLib = 0);

Expand Down Expand Up @@ -528,6 +543,11 @@ public:
/**access range */
RangeData &range(int idx);

/**access relations
* @note added in 1.8
**/
ValueRelationData &valueRelation( int idx );

/**Adds a new overlay to this class. QgsVectorLayer takes ownership of the object
@note this method was added in version 1.1
*/
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -427,6 +427,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
valueRelationKeyColumn->setCurrentIndex( valueRelationKeyColumn->findText( mValueRelationData.mKey ) );
valueRelationValueColumn->setCurrentIndex( valueRelationValueColumn->findText( mValueRelationData.mValue ) );
valueRelationAllowNull->setChecked( mValueRelationData.mAllowNull );
valueRelationOrderByValue->setChecked( mValueRelationData.mOrderByValue );
break;

case QgsVectorLayer::LineEdit:
Expand Down Expand Up @@ -597,6 +598,7 @@ void QgsAttributeTypeDialog::accept()
mValueRelationData.mKey = valueRelationKeyColumn->currentText();
mValueRelationData.mValue = valueRelationValueColumn->currentText();
mValueRelationData.mAllowNull = valueRelationAllowNull->isChecked();
mValueRelationData.mOrderByValue = valueRelationOrderByValue->isChecked();
break;
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -3036,7 +3036,8 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
QString key = editTypeElement.attribute( "key" );
QString value = editTypeElement.attribute( "value" );
bool allowNull = editTypeElement.attribute( "allowNull" ) == "true";
mValueRelations[ name ] = ValueRelationData( id, key, value, allowNull );
bool orderByValue = editTypeElement.attribute( "orderByValue" ) == "true";
mValueRelations[ name ] = ValueRelationData( id, key, value, allowNull, orderByValue );
}
}
}
Expand Down Expand Up @@ -3241,6 +3242,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
editTypeElement.setAttribute( "key", data.mKey );
editTypeElement.setAttribute( "value", data.mValue );
editTypeElement.setAttribute( "allowNull", data.mAllowNull ? "true" : "false" );
editTypeElement.setAttribute( "orderByValue", data.mOrderByValue ? "true" : "false" );
}
break;

Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsvectorlayer.h
Expand Up @@ -121,13 +121,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
struct ValueRelationData
{
ValueRelationData() {}
ValueRelationData( QString layer, QString key, QString value, bool allowNull )
: mLayer( layer ), mKey( key ), mValue( value ), mAllowNull( allowNull ) {}
ValueRelationData( QString layer, QString key, QString value, bool allowNull, bool orderByValue )
: mLayer( layer ), mKey( key ), mValue( value ), mAllowNull( allowNull ), mOrderByValue( orderByValue ) {}

QString mLayer;
QString mKey;
QString mValue;
bool mAllowNull;
bool mOrderByValue;
};

/** Constructor */
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgsattributeeditor.cpp
Expand Up @@ -185,8 +185,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
QMap< QString, QString > map;
if ( layer )
{
int ki = layer->fieldNameIndex( data.mKey );
int vi = layer->fieldNameIndex( data.mValue );
int ki = layer->fieldNameIndex( data.mOrderByValue ? data.mValue : data.mKey );
int vi = layer->fieldNameIndex( data.mOrderByValue ? data.mKey : data.mValue );

if ( data.mAllowNull )
map.insert( nullValue, tr( "(no selection)" ) );
Expand All @@ -207,7 +207,10 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
{
for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ )
{
cb->addItem( it.value(), it.key() );
if ( data.mOrderByValue )
cb->addItem( it.key(), it.value() );
else
cb->addItem( it.value(), it.key() );
}

myWidget = cb;
Expand Down
14 changes: 12 additions & 2 deletions src/ui/qgsattributetypeedit.ui
Expand Up @@ -644,7 +644,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -657,7 +657,7 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<item row="4" column="1">
<widget class="QCheckBox" name="valueRelationAllowNull">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
Expand All @@ -667,6 +667,16 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="valueRelationOrderByValue">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Order by value</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit 985ffbd

Please sign in to comment.