Skip to content
Permalink
Browse files

optionally label attribute editor widgets on top

  • Loading branch information
jef-n committed Jun 4, 2013
1 parent f39486f commit 5d68c30ef8ae17430e3005fc68c92ab060d32753
@@ -99,11 +99,21 @@ bool QgsAttributeTypeDialog::fieldEditable()
return isFieldEditableCheckBox->isChecked();
}

bool QgsAttributeTypeDialog::labelOnTop()
{
return labelOnTopCheckBox->isChecked();
}

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

void QgsAttributeTypeDialog::setLabelOnTop( bool onTop )
{
labelOnTopCheckBox->setChecked( onTop );
}

QPair<QString, QString> QgsAttributeTypeDialog::checkedState()
{
return QPair<QString, QString>( leCheckedState->text(), leUncheckedState->text() );
@@ -100,6 +100,12 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
void setFieldEditable( bool editable );

/**
* Setter for checkbox to label on top
* @param bool onTop
*/
void setLabelOnTop( bool onTop );

/**
* Getter for checked state after editing
* @return string representing the checked
@@ -138,6 +144,11 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
*/
bool fieldEditable();

/**
* Getter for checkbox for label on top of field
*/
bool labelOnTop();

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

bool mFieldEditable;
bool mLabelOnTop;

QMap<QString, QVariant> mValueMap;

@@ -491,6 +491,7 @@ void QgsFieldsProperties::attributeTypeDialog()
attributeTypeDialog.setDateFormat( cfg.mDateFormat );
attributeTypeDialog.setWidgetSize( cfg.mWidgetSize );
attributeTypeDialog.setFieldEditable( cfg.mEditable );
attributeTypeDialog.setLabelOnTop( cfg.mLabelOnTop );

attributeTypeDialog.setIndex( index, cfg.mEditType );

@@ -499,6 +500,7 @@ void QgsFieldsProperties::attributeTypeDialog()

cfg.mEditType = attributeTypeDialog.editType();
cfg.mEditable = attributeTypeDialog.fieldEditable();
cfg.mLabelOnTop = attributeTypeDialog.labelOnTop();

switch ( cfg.mEditType )
{
@@ -846,6 +848,7 @@ void QgsFieldsProperties::apply()
mLayer->setEditType( idx, cfg.mEditType );

mLayer->setFieldEditable( idx, cfg.mEditable );
mLayer->setLabelOnTop( idx, cfg.mLabelOnTop );

switch ( cfg.mEditType )
{
@@ -927,6 +930,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
: mButton( NULL )
{
mEditable = layer->fieldEditable( idx );
mLabelOnTop = layer->labelOnTop( idx );
mValueRelationData = layer->valueRelation( idx );
mValueMap = layer->valueMap( idx );
mRange = layer->range( idx );
@@ -54,6 +54,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
FieldConfig( QgsVectorLayer* layer, int idx );

bool mEditable;
bool mLabelOnTop;
QgsVectorLayer::ValueRelationData mValueRelationData;
QMap<QString, QVariant> mValueMap;
QgsVectorLayer::RangeData mRange;
@@ -1874,6 +1874,9 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
int editable = editTypeElement.attribute( "editable" , "1" ).toInt();
mFieldEditables.insert( name, editable == 1 );

int labelOnTop = editTypeElement.attribute( "labelontop" , "0" ).toInt();
mLabelOnTop.insert( name, labelOnTop == 1 );

switch ( editType )
{
case ValueMap:
@@ -2185,6 +2188,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
editTypeElement.setAttribute( "name", it.key() );
editTypeElement.setAttribute( "type", it.value() );
editTypeElement.setAttribute( "editable", mFieldEditables[ it.key()] ? 1 : 0 );
editTypeElement.setAttribute( "labelontop", mLabelOnTop[ it.key()] ? 1 : 0 );

switch (( EditType ) it.value() )
{
@@ -3053,13 +3057,29 @@ bool QgsVectorLayer::fieldEditable( int idx )
return true;
}

bool QgsVectorLayer::labelOnTop( int idx )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() )
return mLabelOnTop.value( fields[idx].name(), false );
else
return false;
}

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

void QgsVectorLayer::setLabelOnTop( int idx, bool onTop )
{
const QgsFields &fields = pendingFields();
if ( idx >= 0 && idx < fields.count() )
mLabelOnTop[ fields[idx].name()] = onTop;
}

void QgsVectorLayer::addOverlay( QgsVectorOverlay* overlay )
{
mOverlays.push_back( overlay );
@@ -1149,11 +1149,21 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
**/
bool fieldEditable( int idx );

/**label widget on top
* @note added in 1.9
**/
bool labelOnTop( int idx );

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

/**label widget on top
* @note added in 1.9
**/
void setLabelOnTop( int idx, bool onTop );

/**Adds a new overlay to this class. QgsVectorLayer takes ownership of the object
@note this method was added in version 1.1
*/
@@ -1528,6 +1538,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

QMap< QString, EditType > mEditTypes;
QMap< QString, bool> mFieldEditables;
QMap< QString, bool> mLabelOnTop;
QMap< QString, QMap<QString, QVariant> > mValueMaps;
QMap< QString, RangeData > mRanges;
QMap< QString, QPair<QString, QString> > mCheckedStates;
@@ -180,25 +180,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
if ( !myWidget )
continue;

QLabel *mypLabel = new QLabel( mypInnerFrame );
mypInnerLayout->addWidget( mypLabel, index, 0 );
if ( myFieldType == QVariant::Int )
{
mypLabel->setText( myFieldName );
}
else if ( myFieldType == QVariant::Double )
{
mypLabel->setText( myFieldName );
}
else if ( myFieldType == QVariant::LongLong )
{
mypLabel->setText( myFieldName );
}
else //string
{
//any special behaviour for string goes here
mypLabel->setText( myFieldName );
}
QLabel *mypLabel = new QLabel( myFieldName, mypInnerFrame );

if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
@@ -231,8 +213,17 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
}

mypInnerLayout->addWidget( myWidget, index, 1 );
++index;
if ( vl->labelOnTop( fldIdx ) )
{
mypInnerLayout->addWidget( mypLabel, index++, 0, 1, 2 );
mypInnerLayout->addWidget( myWidget, index++, 0, 1, 2 );
}
else
{
mypInnerLayout->addWidget( mypLabel, index, 0 );
mypInnerLayout->addWidget( myWidget, index, 1 );
++index;
}
}

// Set focus to first widget in list, to help entering data without moving the mouse.
@@ -1364,7 +1364,7 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen

int index = 0;

QList<QgsAttributeEditorElement*>children = container->children();
QList<QgsAttributeEditorElement*> children = container->children();

for ( QList<QgsAttributeEditorElement*>::const_iterator it = children.begin(); it != children.end(); ++it )
{
@@ -1381,12 +1381,18 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen

//show attribute alias if available
QString myFieldName = vl->attributeDisplayName( fieldDef->idx() );
QLabel * mypLabel = new QLabel( myContainer );
gbLayout->addWidget( mypLabel, index, 0 );
mypLabel->setText( myFieldName );
QLabel *mypLabel = new QLabel( myFieldName, myContainer );

// add editor widget
gbLayout->addWidget( editor, index, 1 );
if ( vl->labelOnTop( fieldDef->idx() ) )
{
gbLayout->addWidget( mypLabel, index++, 0, 1, 2 );
gbLayout->addWidget( editor, index, 0, 1 , 2 );
}
else
{
gbLayout->addWidget( mypLabel, index, 0 );
gbLayout->addWidget( editor, index, 1 );
}
}

++index;
@@ -7,24 +7,14 @@
<x>0</x>
<y>0</y>
<width>751</width>
<height>451</height>
<height>481</height>
</rect>
</property>
<property name="windowTitle">
<string>Attribute Edit Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="4">
<item row="0" column="0" rowspan="5">
<widget class="QListWidget" name="selectionListWidget">
<item>
<property name="text">
@@ -113,6 +103,16 @@
</item>
</widget>
</item>
<item row="4" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
@@ -123,7 +123,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -894,6 +894,16 @@
</widget>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="labelOnTopCheckBox">
<property name="text">
<string>Label on top</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

0 comments on commit 5d68c30

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