Skip to content
Permalink
Browse files

[FEATURE] allow ordering of value relations by value and

include value relations in sip bindings
  • Loading branch information
jef-n committed Jul 22, 2011
1 parent 5ea8aea commit 985ffbdc5b7a3078d2102520f50aee0a5abc1da9
@@ -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 {
@@ -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);

@@ -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
*/
@@ -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:
@@ -597,6 +598,7 @@ void QgsAttributeTypeDialog::accept()
mValueRelationData.mKey = valueRelationKeyColumn->currentText();
mValueRelationData.mValue = valueRelationValueColumn->currentText();
mValueRelationData.mAllowNull = valueRelationAllowNull->isChecked();
mValueRelationData.mOrderByValue = valueRelationOrderByValue->isChecked();
break;
}

@@ -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 );
}
}
}
@@ -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;

@@ -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 */
@@ -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)" ) );
@@ -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;
@@ -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>
@@ -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>
@@ -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>

0 comments on commit 985ffbd

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