Skip to content

Commit c371647

Browse files
committed
attribute editor layout selection etc.
1 parent 90546b0 commit c371647

File tree

5 files changed

+126
-27
lines changed

5 files changed

+126
-27
lines changed

src/app/qgsattributerelationedit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class APP_EXPORT QgsAttributeRelationEdit: public QWidget, private Ui::QgsAttrib
4545
/**
4646
* Setter for combo cardinality item
4747
*/
48-
void setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData = QVariant() );
48+
void setCardinalityCombo( const QString &cardinalityComboItem, const QVariant &auserData = QVariant() );
4949

5050
/**
5151
* Setter for combo cardinality

src/app/qgsattributesformproperties.cpp

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer,
4444
connect( mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
4545
connect( mAddTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::addTabOrGroupButton );
4646
connect( mRemoveTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::removeTabOrGroupButton );
47+
connect( mEditorLayoutComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged );
48+
connect( pbnSelectEditForm, &QToolButton::clicked, this, &QgsAttributesFormProperties::pbnSelectEditForm_clicked );
4749
}
4850

4951

@@ -57,6 +59,12 @@ void QgsAttributesFormProperties::init()
5759
initAvailableWidgetsTree();
5860
initFormLayoutTree();
5961

62+
mEditorLayoutComboBox->setCurrentIndex( mLayer->editFormConfig().layout() );
63+
mEditorLayoutComboBox_currentIndexChanged( mEditorLayoutComboBox->currentIndex() );
64+
65+
QgsEditFormConfig cfg = mLayer->editFormConfig();
66+
mEditFormLineEdit->setText( cfg.uiForm() );
67+
6068
mAttributeTypeDialog->setEnabled( false );
6169
mAttributeRelationEdit->setEnabled( false );
6270
}
@@ -118,7 +126,8 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
118126
}
119127

120128

121-
void QgsAttributesFormProperties::storeAttributeTypeDialog(){
129+
void QgsAttributesFormProperties::storeAttributeTypeDialog()
130+
{
122131
FieldConfig cfg;
123132

124133
cfg.mEditable = mAttributeTypeDialog->fieldEditable();
@@ -201,7 +210,7 @@ void QgsAttributesFormProperties::loadAttributeRelationEdit()
201210
Q_FOREACH ( const QgsRelation &nmrel, QgsProject::instance()->relationManager()->referencingRelations( relation.referencingLayer() ) )
202211
{
203212
if ( nmrel.fieldPairs().at( 0 ).referencingField() != relation.fieldPairs().at( 0 ).referencingField() )
204-
mAttributeRelationEdit->setCardinalityCombo( QStringLiteral( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() );
213+
mAttributeRelationEdit->setCardinalityCombo( QStringLiteral( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() );
205214
}
206215

207216
mAttributeRelationEdit->setCardinality( cfg.mCardinality );
@@ -353,13 +362,13 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
353362
{
354363
case DnDTreeItemData::Relation:
355364
{
356-
mAttributeTypeDialog->setEnabled( false );
365+
mAttributeTypeDialog->setVisible( false );
357366
loadAttributeRelationEdit();
358367
break;
359368
}
360369
case DnDTreeItemData::Field:
361370
{
362-
mAttributeRelationEdit->setEnabled( false );
371+
mAttributeRelationEdit->setVisible( false );
363372
loadAttributeTypeDialog();
364373
break;
365374
}
@@ -506,6 +515,40 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
506515
return widgetDef;
507516
}
508517

518+
void QgsAttributesFormProperties::mEditorLayoutComboBox_currentIndexChanged( int index )
519+
{
520+
switch ( index )
521+
{
522+
case 0:
523+
mFormLayoutWidget->setVisible( false );
524+
mUiFileFrame->setVisible( false );
525+
break;
526+
527+
case 1:
528+
mFormLayoutWidget->setVisible( true );
529+
mUiFileFrame->setVisible( false );
530+
break;
531+
532+
case 2:
533+
mFormLayoutWidget->setVisible( false );
534+
mUiFileFrame->setVisible( true );
535+
break;
536+
}
537+
}
538+
539+
void QgsAttributesFormProperties::pbnSelectEditForm_clicked()
540+
{
541+
QgsSettings myQSettings;
542+
QString lastUsedDir = myQSettings.value( QStringLiteral( "style/lastUIDir" ), QDir::homePath() ).toString();
543+
QString uifilename = QFileDialog::getOpenFileName( this, tr( "Select edit form" ), lastUsedDir, tr( "UI file" ) + " (*.ui)" );
544+
545+
if ( uifilename.isNull() )
546+
return;
547+
548+
QFileInfo fi( uifilename );
549+
myQSettings.setValue( QStringLiteral( "style/lastUIDir" ), fi.path() );
550+
mEditFormLineEdit->setText( uifilename );
551+
}
509552

510553
void QgsAttributesFormProperties::apply()
511554
{
@@ -570,10 +613,11 @@ void QgsAttributesFormProperties::apply()
570613
editFormConfig.addTab( createAttributeEditorWidget( tabItem, nullptr, false ) );
571614
}
572615

573-
/*
574616
editFormConfig.setUiForm( mEditFormLineEdit->text() );
617+
575618
editFormConfig.setLayout( ( QgsEditFormConfig::EditorLayout ) mEditorLayoutComboBox->currentIndex() );
576619

620+
/*
577621
// Init function configuration
578622
editFormConfig.setInitFunction( mInitFunctionLineEdit->text() );
579623
editFormConfig.setInitCode( mInitCodeEditorPython->text() );

src/app/qgsattributesformproperties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
218218
private slots:
219219
void addTabOrGroupButton();
220220
void removeTabOrGroupButton();
221+
void mEditorLayoutComboBox_currentIndexChanged( int index );
222+
void pbnSelectEditForm_clicked();
221223
};
222224

223225

src/app/qgssourcefieldsproperties.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ QgsSourceFieldsProperties::~QgsSourceFieldsProperties()
6161
void QgsSourceFieldsProperties::init()
6262
{
6363
loadRows();
64-
65-
//not used here: mEditorLayoutComboBox->setCurrentIndex( mLayer->editFormConfig().layout() );
66-
//used here????? mFormSuppressCmbBx->setCurrentIndex( mLayer->editFormConfig().suppress() );
67-
//not used here: loadAttributeEditorTree();
6864
}
6965

7066
void QgsSourceFieldsProperties::loadRows()

src/ui/qgsattributesformproperties.ui

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,53 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>625</width>
10-
<height>359</height>
9+
<width>653</width>
10+
<height>556</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QHBoxLayout" name="horizontalLayout">
17-
<property name="leftMargin">
18-
<number>0</number>
19-
</property>
20-
<property name="topMargin">
21-
<number>0</number>
22-
</property>
23-
<property name="rightMargin">
24-
<number>0</number>
25-
</property>
26-
<property name="bottomMargin">
27-
<number>0</number>
28-
</property>
29-
<item>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<widget class="QWidget" name="widget_2" native="true">
19+
<property name="maximumSize">
20+
<size>
21+
<width>16777215</width>
22+
<height>40</height>
23+
</size>
24+
</property>
25+
<layout class="QHBoxLayout" name="horizontalLayout">
26+
<item>
27+
<widget class="QLabel" name="label">
28+
<property name="text">
29+
<string>Attribute editor layout</string>
30+
</property>
31+
</widget>
32+
</item>
33+
<item>
34+
<widget class="QComboBox" name="mEditorLayoutComboBox">
35+
<item>
36+
<property name="text">
37+
<string>Autogenerate</string>
38+
</property>
39+
</item>
40+
<item>
41+
<property name="text">
42+
<string>Drag and drop designer</string>
43+
</property>
44+
</item>
45+
<item>
46+
<property name="text">
47+
<string>Provide ui-file</string>
48+
</property>
49+
</item>
50+
</widget>
51+
</item>
52+
</layout>
53+
</widget>
54+
</item>
55+
<item row="2" column="0">
3056
<widget class="QSplitter" name="splitter">
3157
<property name="orientation">
3258
<enum>Qt::Horizontal</enum>
@@ -45,7 +71,9 @@
4571
</widget>
4672
</item>
4773
<item row="0" column="1" rowspan="6">
48-
<widget class="QWidget" name="mFormLayoutWidget" native="true"/>
74+
<widget class="QWidget" name="mFormLayoutWidget" native="true">
75+
<zorder>pushButton</zorder>
76+
</widget>
4977
</item>
5078
<item row="2" column="2">
5179
<widget class="QToolButton" name="mRemoveTabOrGroupButton">
@@ -81,6 +109,35 @@
81109
</widget>
82110
</widget>
83111
</item>
112+
<item row="1" column="0">
113+
<widget class="QWidget" name="mUiFileFrame" native="true">
114+
<property name="maximumSize">
115+
<size>
116+
<width>16777215</width>
117+
<height>40</height>
118+
</size>
119+
</property>
120+
<layout class="QHBoxLayout" name="horizontalLayout_2">
121+
<item>
122+
<widget class="QLabel" name="label_2">
123+
<property name="text">
124+
<string>Edit UI</string>
125+
</property>
126+
</widget>
127+
</item>
128+
<item>
129+
<widget class="QLineEdit" name="mEditFormLineEdit"/>
130+
</item>
131+
<item>
132+
<widget class="QToolButton" name="pbnSelectEditForm">
133+
<property name="text">
134+
<string>...</string>
135+
</property>
136+
</widget>
137+
</item>
138+
</layout>
139+
</widget>
140+
</item>
84141
</layout>
85142
</widget>
86143
<resources>

0 commit comments

Comments
 (0)