Skip to content

Commit 7e699f1

Browse files
committedNov 12, 2017
improve layout in Python init function editor (fix #17428)
1 parent 944d2f4 commit 7e699f1

File tree

3 files changed

+84
-142
lines changed

3 files changed

+84
-142
lines changed
 

‎src/app/qgsattributesforminitcode.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ QgsAttributesFormInitCode::QgsAttributesFormInitCode()
2929
mInitCodeSourceComboBox->addItem( tr( "Provide code in this dialog" ) );
3030
mInitCodeSourceComboBox->addItem( tr( "Load from the environment" ) );
3131

32-
connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
33-
connect( pbtnSelectInitFilePath, &QToolButton::clicked, this, &QgsAttributesFormInitCode::pbtnSelectInitFilePath_clicked );
32+
QgsSettings settings;
33+
mInitFileWidget->setDefaultRoot( settings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString() );
34+
mInitFileWidget->setDialogTitle( tr( "Select Python File" ) );
35+
mInitFileWidget->setFilter( tr( "Python files (*.py *.PY)" ) );
3436

37+
connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
3538
}
3639

3740
void QgsAttributesFormInitCode::setCodeSource( QgsEditFormConfig::PythonInitCodeSource initCodeSource )
@@ -46,7 +49,7 @@ void QgsAttributesFormInitCode::setInitFunction( const QString &initFunction )
4649
}
4750
void QgsAttributesFormInitCode::setInitFilePath( const QString &initFilePath )
4851
{
49-
mInitFilePathLineEdit->setText( initFilePath );
52+
mInitFileWidget->setFilePath( initFilePath );
5053
}
5154
void QgsAttributesFormInitCode::setInitCode( const QString &initCode )
5255
{
@@ -64,7 +67,7 @@ QString QgsAttributesFormInitCode::initFunction() const
6467
}
6568
QString QgsAttributesFormInitCode::initFilePath() const
6669
{
67-
return mInitFilePathLineEdit->text();
70+
return mInitFileWidget->filePath();
6871
}
6972
QString QgsAttributesFormInitCode::initCode() const
7073
{
@@ -74,23 +77,7 @@ QString QgsAttributesFormInitCode::initCode() const
7477
void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int codeSource )
7578
{
7679
mInitFunctionContainer->setVisible( codeSource != QgsEditFormConfig::CodeSourceNone );
77-
mInitFilePathLineEdit->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
7880
mInitFilePathLabel->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
79-
pbtnSelectInitFilePath->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
81+
mInitFileWidget->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
8082
mInitCodeEditorPython->setVisible( codeSource == QgsEditFormConfig::CodeSourceDialog );
8183
}
82-
83-
void QgsAttributesFormInitCode::pbtnSelectInitFilePath_clicked( )
84-
{
85-
QgsSettings myQSettings;
86-
QString lastUsedDir = myQSettings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString();
87-
QString pyfilename = QFileDialog::getOpenFileName( this, tr( "Select Python file" ), lastUsedDir, tr( "Python file" ) + " (*.py)" );
88-
89-
if ( pyfilename.isNull() )
90-
return;
91-
92-
QFileInfo fi( pyfilename );
93-
myQSettings.setValue( QStringLiteral( "style/lastInitFilePathDir" ), fi.path() );
94-
mInitFilePathLineEdit->setText( pyfilename );
95-
}
96-

‎src/app/qgsattributesforminitcode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class APP_EXPORT QgsAttributesFormInitCode: public QDialog, private Ui::QgsAttri
4949

5050
private slots:
5151
void mInitCodeSourceComboBox_currentIndexChanged( int codeSource );
52-
void pbtnSelectInitFilePath_clicked();
5352
};
5453

5554
#endif // QGSATTRIBUTESFORMINITCODE_H

‎src/ui/qgsattributesforminitcode.ui

Lines changed: 76 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,96 @@
77
<x>0</x>
88
<y>0</y>
99
<width>400</width>
10-
<height>300</height>
10+
<height>283</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Python Init Code Configuration</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
17-
<item row="1" column="0">
18-
<widget class="QWidget" name="mInitFunctionContainer" native="true">
19-
<property name="sizePolicy">
20-
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
21-
<horstretch>0</horstretch>
22-
<verstretch>0</verstretch>
23-
</sizepolicy>
16+
<layout class="QGridLayout" name="gridLayout_2">
17+
<item row="0" column="0">
18+
<widget class="QLabel" name="label_3">
19+
<property name="toolTip">
20+
<string>The function code of the function can be loaded from the source code entered
21+
in this dialog, from an external python file or from the environment (for example
22+
from a plugin or from startup.py).
23+
24+
An example is:
25+
26+
from qgis.PyQt.QtWidgets import QWidget
27+
28+
def my_form_open(dialog, layer, feature):
29+
geom = feature.geometry()
30+
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)
31+
32+
Reference in function name: my_form_open
33+
34+
</string>
2435
</property>
25-
<property name="maximumSize">
26-
<size>
27-
<width>16777215</width>
28-
<height>50</height>
29-
</size>
36+
<property name="text">
37+
<string>Python Init function</string>
3038
</property>
31-
<layout class="QHBoxLayout" name="horizontalLayout_4">
39+
</widget>
40+
</item>
41+
<item row="0" column="1" colspan="2">
42+
<widget class="QComboBox" name="mInitCodeSourceComboBox">
43+
<property name="toolTip">
44+
<string>The function code of the function can be loaded from the source code entered
45+
in this dialog, from an external python file or from the environment (for example
46+
from a plugin or from startup.py).
47+
48+
An example is:
49+
50+
rom qgis.PyQt.QtWidgets import QWidget
51+
52+
def my_form_open(dialog, layer, feature):
53+
geom = feature.geometry()
54+
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)
55+
56+
Reference in function name: my_form_open
57+
58+
</string>
59+
</property>
60+
</widget>
61+
</item>
62+
<item row="1" column="0" colspan="3">
63+
<widget class="QWidget" name="mInitFunctionContainer" native="true">
64+
<layout class="QGridLayout" name="gridLayout">
3265
<property name="leftMargin">
3366
<number>0</number>
3467
</property>
35-
<property name="topMargin">
36-
<number>0</number>
37-
</property>
3868
<property name="rightMargin">
3969
<number>0</number>
4070
</property>
41-
<property name="bottomMargin">
42-
<number>0</number>
43-
</property>
44-
<item>
45-
<widget class="QLabel" name="mInitFunctionLabel">
46-
<property name="text">
47-
<string>Function name</string>
48-
</property>
49-
</widget>
50-
</item>
51-
<item>
52-
<widget class="QLineEdit" name="mInitFunctionLineEdit">
53-
<property name="toolTip">
54-
<string>Enter the name of the form init function.</string>
55-
</property>
56-
</widget>
57-
</item>
58-
<item>
71+
<item row="0" column="0">
5972
<widget class="QLabel" name="mInitFilePathLabel">
6073
<property name="text">
6174
<string>External file</string>
6275
</property>
6376
</widget>
6477
</item>
65-
<item>
66-
<widget class="QLineEdit" name="mInitFilePathLineEdit"/>
78+
<item row="0" column="1">
79+
<widget class="QgsFileWidget" name="mInitFileWidget" native="true"/>
6780
</item>
68-
<item>
69-
<widget class="QToolButton" name="pbtnSelectInitFilePath">
81+
<item row="1" column="0">
82+
<widget class="QLabel" name="mInitFunctionLabel">
7083
<property name="text">
71-
<string></string>
84+
<string>Function name</string>
7285
</property>
7386
</widget>
7487
</item>
75-
<item>
76-
<spacer name="horizontalSpacer_4">
77-
<property name="orientation">
78-
<enum>Qt::Horizontal</enum>
79-
</property>
80-
<property name="sizeHint" stdset="0">
81-
<size>
82-
<width>0</width>
83-
<height>0</height>
84-
</size>
88+
<item row="1" column="1">
89+
<widget class="QLineEdit" name="mInitFunctionLineEdit">
90+
<property name="toolTip">
91+
<string>Enter the name of the form init function.</string>
8592
</property>
86-
</spacer>
93+
</widget>
8794
</item>
8895
</layout>
8996
</widget>
9097
</item>
91-
<item row="4" column="0">
98+
<item row="5" column="0" colspan="3">
9299
<widget class="QDialogButtonBox" name="buttonBox">
93-
<property name="maximumSize">
94-
<size>
95-
<width>16777215</width>
96-
<height>50</height>
97-
</size>
98-
</property>
99100
<property name="orientation">
100101
<enum>Qt::Horizontal</enum>
101102
</property>
@@ -104,75 +105,25 @@
104105
</property>
105106
</widget>
106107
</item>
107-
<item row="2" column="0">
108-
<widget class="QgsCodeEditorPython" name="mInitCodeEditorPython" native="true"/>
109-
</item>
110-
<item row="0" column="0">
111-
<widget class="QWidget" name="mInitCodeSourceContainter" native="true">
112-
<property name="maximumSize">
113-
<size>
114-
<width>16777215</width>
115-
<height>50</height>
116-
</size>
108+
<item row="3" column="0" colspan="3">
109+
<widget class="QgsCodeEditorPython" name="mInitCodeEditorPython" native="true">
110+
<property name="sizePolicy">
111+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
112+
<horstretch>0</horstretch>
113+
<verstretch>1</verstretch>
114+
</sizepolicy>
117115
</property>
118-
<layout class="QHBoxLayout" name="horizontalLayout">
119-
<item>
120-
<widget class="QLabel" name="label_3">
121-
<property name="toolTip">
122-
<string>The function code of the function can be loaded from the source code entered
123-
in this dialog, from an external python file or from the environment (for example
124-
from a plugin or from startup.py).
125-
126-
An example is:
127-
128-
rom qgis.PyQt.QtWidgets import QWidget
129-
130-
def my_form_open(dialog, layer, feature):
131-
geom = feature.geometry()
132-
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)
133-
134-
Reference in function name: my_form_open
135-
136-
</string>
137-
</property>
138-
<property name="text">
139-
<string>Python Init function</string>
140-
</property>
141-
</widget>
142-
</item>
143-
<item>
144-
<widget class="QComboBox" name="mInitCodeSourceComboBox">
145-
<property name="toolTip">
146-
<string>The function code of the function can be loaded from the source code entered
147-
in this dialog, from an external python file or from the environment (for example
148-
from a plugin or from startup.py).
149-
150-
An example is:
151-
152-
rom qgis.PyQt.QtWidgets import QWidget
153-
154-
def my_form_open(dialog, layer, feature):
155-
geom = feature.geometry()
156-
control = dialog.findChild(QWidget,&quot;MyLineEdit&quot;)
157-
158-
Reference in function name: my_form_open
159-
160-
</string>
161-
</property>
162-
</widget>
163-
</item>
164-
</layout>
165116
</widget>
166117
</item>
167-
<item row="3" column="0">
118+
<item row="4" column="1">
168119
<spacer name="verticalSpacer">
169120
<property name="orientation">
170121
<enum>Qt::Vertical</enum>
171122
</property>
172123
<property name="sizeHint" stdset="0">
173124
<size>
174125
<width>20</width>
175-
<height>40</height>
126+
<height>0</height>
176127
</size>
177128
</property>
178129
</spacer>
@@ -186,6 +137,11 @@ Reference in function name: my_form_open
186137
<header>qgscodeeditorpython.h</header>
187138
<container>1</container>
188139
</customwidget>
140+
<customwidget>
141+
<class>QgsFileWidget</class>
142+
<extends>QWidget</extends>
143+
<header>qgsfilewidget.h</header>
144+
</customwidget>
189145
</customwidgets>
190146
<resources/>
191147
<connections>
@@ -196,8 +152,8 @@ Reference in function name: my_form_open
196152
<slot>accept()</slot>
197153
<hints>
198154
<hint type="sourcelabel">
199-
<x>254</x>
200-
<y>293</y>
155+
<x>248</x>
156+
<y>254</y>
201157
</hint>
202158
<hint type="destinationlabel">
203159
<x>157</x>

0 commit comments

Comments
 (0)
Please sign in to comment.