Skip to content

Commit eb0642e

Browse files
committedOct 9, 2011
Add signal for expression parsed in widget; fixed enabling of controls in labeling gui; comments
1 parent 107247e commit eb0642e

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed
 

‎src/app/qgslabelinggui.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent )
3838
: QDialog( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
3939
{
40+
if ( !layer ) return;
41+
4042
setupUi( this );
4143

4244
connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
@@ -63,6 +65,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
6365
Q_ASSERT( 0 && "NOOOO!" );
6466
}
6567

68+
//mTabWidget->setEnabled( chkEnableLabeling->isChecked() );
6669
chkMergeLines->setEnabled( layer->geometryType() == QGis::Line );
6770
label_19->setEnabled( layer->geometryType() != QGis::Point );
6871
mMinSizeSpinBox->setEnabled( layer->geometryType() != QGis::Point );
@@ -71,11 +74,16 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
7174
QgsPalLayerSettings lyr;
7275
lyr.readFromLayer( layer );
7376
populateFieldNames();
77+
populateDataDefinedCombos( lyr );
78+
79+
chkEnableLabeling->setChecked( lyr.enabled );
80+
mTabWidget->setEnabled( lyr.enabled );
81+
cboFieldName->setEnabled( lyr.enabled );
82+
btnExpression->setEnabled( lyr.enabled );
7483

7584
//Add the current expression to the bottom of the list.
7685
if (lyr.isExpression and !lyr.fieldName.isEmpty())
7786
cboFieldName->addItem(lyr.fieldName);
78-
populateDataDefinedCombos( lyr );
7987

8088
// placement
8189
int distUnitIndex = lyr.distInMapUnits ? 1 : 0;
@@ -485,6 +493,8 @@ void QgsLabelingGui::showEngineConfigDialog()
485493

486494
void QgsLabelingGui::showExpressionDialog()
487495
{
496+
//TODO extract this out to a dialog.
497+
488498
QDialog* dlg = new QDialog();
489499
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
490500
| QDialogButtonBox::Cancel);
@@ -495,6 +505,8 @@ void QgsLabelingGui::showExpressionDialog()
495505
layout->addWidget(buttonBox);
496506
connect(buttonBox,SIGNAL( accepted() ),dlg,SLOT( accept() ) );
497507
connect(buttonBox,SIGNAL( rejected() ),dlg,SLOT( reject() ) );
508+
QPushButton* okButuon = buttonBox->button(QDialogButtonBox::Ok);
509+
connect(builder, SIGNAL(expressionParsed(bool)), okButuon, SLOT(setEnabled(bool)));
498510

499511
// Set the current expression using the selected text in the combo box.
500512
builder->setExpressionString(this->cboFieldName->currentText());

‎src/gui/qgsexpressionbuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
188188
if ( exp.hasParserError())
189189
{
190190
this->txtExpressionString->setStyleSheet("background-color: rgba(255, 6, 10, 75);");
191+
this->txtExpressionString->setToolTip(exp.parserErrorString());
192+
emit expressionParsed(false);
191193
}
192194
else
193195
{
194196
this->txtExpressionString->setStyleSheet("");
197+
this->txtExpressionString->setToolTip("");
198+
emit expressionParsed(true);
195199
}
196200
}
197201

‎src/gui/qgsexpressionbuilder.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class QgsExpressionItem : public QStandardItem
7878
QgsExpressionItem::ItemType mType;
7979
};
8080

81+
/** A reusable widget that can be used to build a expression string. */
8182
class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuilder {
8283
Q_OBJECT
8384
public:
@@ -107,7 +108,10 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil
107108
QString helpText = "",
108109
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode);
109110

110-
/** Does the expression used in the widget have any errors */
111+
/** Does the expression used in the widget have any errors
112+
* @note Users of this widget can check this to see if they should let the
113+
* user move forward.
114+
*/
111115
bool hasExpressionError();
112116

113117
public slots:
@@ -116,6 +120,9 @@ public slots:
116120
void on_expressionTree_doubleClicked(const QModelIndex &index);
117121
void on_txtExpressionString_textChanged();
118122

123+
signals:
124+
void expressionParsed(bool isVaild);
125+
119126
private:
120127
void fillFieldValues(int fieldIndex, int countLimit);
121128

‎src/ui/qgsexpressionbuilder.ui

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>589</width>
10-
<height>604</height>
9+
<width>533</width>
10+
<height>591</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -80,7 +80,7 @@
8080
<item>
8181
<widget class="QLabel" name="mValueListLabel">
8282
<property name="text">
83-
<string>Field Values</string>
83+
<string>&lt;b&gt;Field Values&lt;/b&gt;</string>
8484
</property>
8585
</widget>
8686
</item>
@@ -149,8 +149,8 @@
149149
<rect>
150150
<x>0</x>
151151
<y>0</y>
152-
<width>277</width>
153-
<height>140</height>
152+
<width>249</width>
153+
<height>127</height>
154154
</rect>
155155
</property>
156156
<layout class="QGridLayout" name="gridLayout_4">
@@ -187,8 +187,6 @@
187187
</widget>
188188
</item>
189189
</layout>
190-
<zorder>txtHelpText</zorder>
191-
<zorder>scrollArea</zorder>
192190
</widget>
193191
</item>
194192
</layout>
@@ -360,7 +358,7 @@
360358
</size>
361359
</property>
362360
<property name="title">
363-
<string>Expression =</string>
361+
<string>Expression</string>
364362
</property>
365363
<layout class="QGridLayout" name="gridLayout_2">
366364
<property name="leftMargin">

‎src/ui/qgslabelingguibase.ui

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
</property>
8080
<widget class="QWidget" name="tab_3">
8181
<attribute name="icon">
82-
<iconset>
82+
<iconset resource="../../images/images.qrc">
8383
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
8484
</attribute>
8585
<attribute name="title">
@@ -390,7 +390,7 @@
390390
</widget>
391391
<widget class="QWidget" name="tab">
392392
<attribute name="icon">
393-
<iconset>
393+
<iconset resource="../../images/images.qrc">
394394
<normaloff>:/images/themes/default/propertyicons/general.png</normaloff>:/images/themes/default/propertyicons/general.png</iconset>
395395
</attribute>
396396
<attribute name="title">
@@ -856,7 +856,7 @@
856856
</widget>
857857
<widget class="QWidget" name="tab_4">
858858
<attribute name="icon">
859-
<iconset>
859+
<iconset resource="../../images/images.qrc">
860860
<normaloff>:/images/themes/gis/mActionOpenTable.png</normaloff>:/images/themes/gis/mActionOpenTable.png</iconset>
861861
</attribute>
862862
<attribute name="title">
@@ -1096,6 +1096,9 @@
10961096
<property name="enabled">
10971097
<bool>false</bool>
10981098
</property>
1099+
<property name="editable">
1100+
<bool>false</bool>
1101+
</property>
10991102
</widget>
11001103
</item>
11011104
<item>
@@ -1180,32 +1183,32 @@
11801183
<connection>
11811184
<sender>chkEnableLabeling</sender>
11821185
<signal>clicked(bool)</signal>
1183-
<receiver>mTabWidget</receiver>
1186+
<receiver>cboFieldName</receiver>
11841187
<slot>setEnabled(bool)</slot>
11851188
<hints>
11861189
<hint type="sourcelabel">
1187-
<x>59</x>
1188-
<y>22</y>
1190+
<x>127</x>
1191+
<y>25</y>
11891192
</hint>
11901193
<hint type="destinationlabel">
1191-
<x>91</x>
1192-
<y>89</y>
1194+
<x>248</x>
1195+
<y>26</y>
11931196
</hint>
11941197
</hints>
11951198
</connection>
11961199
<connection>
11971200
<sender>chkEnableLabeling</sender>
11981201
<signal>clicked(bool)</signal>
1199-
<receiver>cboFieldName</receiver>
1202+
<receiver>mTabWidget</receiver>
12001203
<slot>setEnabled(bool)</slot>
12011204
<hints>
12021205
<hint type="sourcelabel">
1203-
<x>127</x>
1204-
<y>25</y>
1206+
<x>59</x>
1207+
<y>22</y>
12051208
</hint>
12061209
<hint type="destinationlabel">
1207-
<x>248</x>
1208-
<y>26</y>
1210+
<x>91</x>
1211+
<y>89</y>
12091212
</hint>
12101213
</hints>
12111214
</connection>

0 commit comments

Comments
 (0)
Please sign in to comment.