Skip to content

Commit

Permalink
optionally label attribute editor widgets on top
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 4, 2013
1 parent f39486f commit 5d68c30
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 40 deletions.
10 changes: 10 additions & 0 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -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() );
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsattributetypedialog.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -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 );

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

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

switch ( cfg.mEditType )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsfieldsproperties.h
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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 );
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 12 additions & 21 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions src/gui/qgsattributeeditor.cpp
Expand Up @@ -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 )
{
Expand All @@ -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;
Expand Down
36 changes: 23 additions & 13 deletions src/ui/qgsattributetypeedit.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -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">
Expand Down Expand Up @@ -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/>
Expand Down

0 comments on commit 5d68c30

Please sign in to comment.