Skip to content

Commit 5d68c30

Browse files
committed
optionally label attribute editor widgets on top
1 parent f39486f commit 5d68c30

File tree

9 files changed

+105
-40
lines changed

9 files changed

+105
-40
lines changed

src/app/qgsattributetypedialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,21 @@ bool QgsAttributeTypeDialog::fieldEditable()
9999
return isFieldEditableCheckBox->isChecked();
100100
}
101101

102+
bool QgsAttributeTypeDialog::labelOnTop()
103+
{
104+
return labelOnTopCheckBox->isChecked();
105+
}
106+
102107
void QgsAttributeTypeDialog::setFieldEditable( bool editable )
103108
{
104109
isFieldEditableCheckBox->setChecked( editable );
105110
}
106111

112+
void QgsAttributeTypeDialog::setLabelOnTop( bool onTop )
113+
{
114+
labelOnTopCheckBox->setChecked( onTop );
115+
}
116+
107117
QPair<QString, QString> QgsAttributeTypeDialog::checkedState()
108118
{
109119
return QPair<QString, QString>( leCheckedState->text(), leUncheckedState->text() );

src/app/qgsattributetypedialog.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
100100
*/
101101
void setFieldEditable( bool editable );
102102

103+
/**
104+
* Setter for checkbox to label on top
105+
* @param bool onTop
106+
*/
107+
void setLabelOnTop( bool onTop );
108+
103109
/**
104110
* Getter for checked state after editing
105111
* @return string representing the checked
@@ -138,6 +144,11 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
138144
*/
139145
bool fieldEditable();
140146

147+
/**
148+
* Getter for checkbox for label on top of field
149+
*/
150+
bool labelOnTop();
151+
141152
private slots:
142153
/**
143154
* Slot to handle change of index in combobox to select correct page
@@ -194,6 +205,7 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
194205
void updateMap( const QMap<QString, QVariant> &map );
195206

196207
bool mFieldEditable;
208+
bool mLabelOnTop;
197209

198210
QMap<QString, QVariant> mValueMap;
199211

src/app/qgsfieldsproperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ void QgsFieldsProperties::attributeTypeDialog()
491491
attributeTypeDialog.setDateFormat( cfg.mDateFormat );
492492
attributeTypeDialog.setWidgetSize( cfg.mWidgetSize );
493493
attributeTypeDialog.setFieldEditable( cfg.mEditable );
494+
attributeTypeDialog.setLabelOnTop( cfg.mLabelOnTop );
494495

495496
attributeTypeDialog.setIndex( index, cfg.mEditType );
496497

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

500501
cfg.mEditType = attributeTypeDialog.editType();
501502
cfg.mEditable = attributeTypeDialog.fieldEditable();
503+
cfg.mLabelOnTop = attributeTypeDialog.labelOnTop();
502504

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

848850
mLayer->setFieldEditable( idx, cfg.mEditable );
851+
mLayer->setLabelOnTop( idx, cfg.mLabelOnTop );
849852

850853
switch ( cfg.mEditType )
851854
{
@@ -927,6 +930,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
927930
: mButton( NULL )
928931
{
929932
mEditable = layer->fieldEditable( idx );
933+
mLabelOnTop = layer->labelOnTop( idx );
930934
mValueRelationData = layer->valueRelation( idx );
931935
mValueMap = layer->valueMap( idx );
932936
mRange = layer->range( idx );

src/app/qgsfieldsproperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
5454
FieldConfig( QgsVectorLayer* layer, int idx );
5555

5656
bool mEditable;
57+
bool mLabelOnTop;
5758
QgsVectorLayer::ValueRelationData mValueRelationData;
5859
QMap<QString, QVariant> mValueMap;
5960
QgsVectorLayer::RangeData mRange;

src/core/qgsvectorlayer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,9 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
18741874
int editable = editTypeElement.attribute( "editable" , "1" ).toInt();
18751875
mFieldEditables.insert( name, editable == 1 );
18761876

1877+
int labelOnTop = editTypeElement.attribute( "labelontop" , "0" ).toInt();
1878+
mLabelOnTop.insert( name, labelOnTop == 1 );
1879+
18771880
switch ( editType )
18781881
{
18791882
case ValueMap:
@@ -2185,6 +2188,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
21852188
editTypeElement.setAttribute( "name", it.key() );
21862189
editTypeElement.setAttribute( "type", it.value() );
21872190
editTypeElement.setAttribute( "editable", mFieldEditables[ it.key()] ? 1 : 0 );
2191+
editTypeElement.setAttribute( "labelontop", mLabelOnTop[ it.key()] ? 1 : 0 );
21882192

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

3060+
bool QgsVectorLayer::labelOnTop( int idx )
3061+
{
3062+
const QgsFields &fields = pendingFields();
3063+
if ( idx >= 0 && idx < fields.count() )
3064+
return mLabelOnTop.value( fields[idx].name(), false );
3065+
else
3066+
return false;
3067+
}
3068+
30563069
void QgsVectorLayer::setFieldEditable( int idx, bool editable )
30573070
{
30583071
const QgsFields &fields = pendingFields();
30593072
if ( idx >= 0 && idx < fields.count() )
30603073
mFieldEditables[ fields[idx].name()] = editable;
30613074
}
30623075

3076+
void QgsVectorLayer::setLabelOnTop( int idx, bool onTop )
3077+
{
3078+
const QgsFields &fields = pendingFields();
3079+
if ( idx >= 0 && idx < fields.count() )
3080+
mLabelOnTop[ fields[idx].name()] = onTop;
3081+
}
3082+
30633083
void QgsVectorLayer::addOverlay( QgsVectorOverlay* overlay )
30643084
{
30653085
mOverlays.push_back( overlay );

src/core/qgsvectorlayer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,21 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11491149
**/
11501150
bool fieldEditable( int idx );
11511151

1152+
/**label widget on top
1153+
* @note added in 1.9
1154+
**/
1155+
bool labelOnTop( int idx );
1156+
11521157
/**set edit widget editable
11531158
* @note added in 1.9
11541159
**/
11551160
void setFieldEditable( int idx, bool editable );
11561161

1162+
/**label widget on top
1163+
* @note added in 1.9
1164+
**/
1165+
void setLabelOnTop( int idx, bool onTop );
1166+
11571167
/**Adds a new overlay to this class. QgsVectorLayer takes ownership of the object
11581168
@note this method was added in version 1.1
11591169
*/
@@ -1528,6 +1538,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
15281538

15291539
QMap< QString, EditType > mEditTypes;
15301540
QMap< QString, bool> mFieldEditables;
1541+
QMap< QString, bool> mLabelOnTop;
15311542
QMap< QString, QMap<QString, QVariant> > mValueMaps;
15321543
QMap< QString, RangeData > mRanges;
15331544
QMap< QString, QPair<QString, QString> > mCheckedStates;

src/gui/qgsattributedialog.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
180180
if ( !myWidget )
181181
continue;
182182

183-
QLabel *mypLabel = new QLabel( mypInnerFrame );
184-
mypInnerLayout->addWidget( mypLabel, index, 0 );
185-
if ( myFieldType == QVariant::Int )
186-
{
187-
mypLabel->setText( myFieldName );
188-
}
189-
else if ( myFieldType == QVariant::Double )
190-
{
191-
mypLabel->setText( myFieldName );
192-
}
193-
else if ( myFieldType == QVariant::LongLong )
194-
{
195-
mypLabel->setText( myFieldName );
196-
}
197-
else //string
198-
{
199-
//any special behaviour for string goes here
200-
mypLabel->setText( myFieldName );
201-
}
183+
QLabel *mypLabel = new QLabel( myFieldName, mypInnerFrame );
202184

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

234-
mypInnerLayout->addWidget( myWidget, index, 1 );
235-
++index;
216+
if ( vl->labelOnTop( fldIdx ) )
217+
{
218+
mypInnerLayout->addWidget( mypLabel, index++, 0, 1, 2 );
219+
mypInnerLayout->addWidget( myWidget, index++, 0, 1, 2 );
220+
}
221+
else
222+
{
223+
mypInnerLayout->addWidget( mypLabel, index, 0 );
224+
mypInnerLayout->addWidget( myWidget, index, 1 );
225+
++index;
226+
}
236227
}
237228

238229
// Set focus to first widget in list, to help entering data without moving the mouse.

src/gui/qgsattributeeditor.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElemen
13641364

13651365
int index = 0;
13661366

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

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

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

1388-
// add editor widget
1389-
gbLayout->addWidget( editor, index, 1 );
1386+
if ( vl->labelOnTop( fieldDef->idx() ) )
1387+
{
1388+
gbLayout->addWidget( mypLabel, index++, 0, 1, 2 );
1389+
gbLayout->addWidget( editor, index, 0, 1 , 2 );
1390+
}
1391+
else
1392+
{
1393+
gbLayout->addWidget( mypLabel, index, 0 );
1394+
gbLayout->addWidget( editor, index, 1 );
1395+
}
13901396
}
13911397

13921398
++index;

src/ui/qgsattributetypeedit.ui

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,14 @@
77
<x>0</x>
88
<y>0</y>
99
<width>751</width>
10-
<height>451</height>
10+
<height>481</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Attribute Edit Dialog</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_4">
17-
<item row="3" column="1">
18-
<widget class="QDialogButtonBox" name="buttonBox">
19-
<property name="orientation">
20-
<enum>Qt::Horizontal</enum>
21-
</property>
22-
<property name="standardButtons">
23-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
24-
</property>
25-
</widget>
26-
</item>
27-
<item row="0" column="0" rowspan="4">
17+
<item row="0" column="0" rowspan="5">
2818
<widget class="QListWidget" name="selectionListWidget">
2919
<item>
3020
<property name="text">
@@ -113,6 +103,16 @@
113103
</item>
114104
</widget>
115105
</item>
106+
<item row="4" column="1">
107+
<widget class="QDialogButtonBox" name="buttonBox">
108+
<property name="orientation">
109+
<enum>Qt::Horizontal</enum>
110+
</property>
111+
<property name="standardButtons">
112+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
113+
</property>
114+
</widget>
115+
</item>
116116
<item row="0" column="1">
117117
<widget class="QCheckBox" name="isFieldEditableCheckBox">
118118
<property name="text">
@@ -123,7 +123,7 @@
123123
</property>
124124
</widget>
125125
</item>
126-
<item row="1" column="1">
126+
<item row="2" column="1">
127127
<widget class="QStackedWidget" name="stackedWidget">
128128
<property name="sizePolicy">
129129
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@@ -894,6 +894,16 @@
894894
</widget>
895895
</widget>
896896
</item>
897+
<item row="1" column="1">
898+
<widget class="QCheckBox" name="labelOnTopCheckBox">
899+
<property name="text">
900+
<string>Label on top</string>
901+
</property>
902+
<property name="checked">
903+
<bool>false</bool>
904+
</property>
905+
</widget>
906+
</item>
897907
</layout>
898908
</widget>
899909
<resources/>

0 commit comments

Comments
 (0)