Skip to content

Commit

Permalink
Add signal for expression parsed in widget; fixed enabling of control…
Browse files Browse the repository at this point in the history
…s in labeling gui; comments
  • Loading branch information
NathanW2 committed Oct 9, 2011
1 parent 107247e commit eb0642e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
14 changes: 13 additions & 1 deletion src/app/qgslabelinggui.cpp
Expand Up @@ -37,6 +37,8 @@
QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent )
: QDialog( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
{
if ( !layer ) return;

setupUi( this );

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

//mTabWidget->setEnabled( chkEnableLabeling->isChecked() );
chkMergeLines->setEnabled( layer->geometryType() == QGis::Line );
label_19->setEnabled( layer->geometryType() != QGis::Point );
mMinSizeSpinBox->setEnabled( layer->geometryType() != QGis::Point );
Expand All @@ -71,11 +74,16 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
QgsPalLayerSettings lyr;
lyr.readFromLayer( layer );
populateFieldNames();
populateDataDefinedCombos( lyr );

chkEnableLabeling->setChecked( lyr.enabled );
mTabWidget->setEnabled( lyr.enabled );
cboFieldName->setEnabled( lyr.enabled );
btnExpression->setEnabled( lyr.enabled );

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

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

void QgsLabelingGui::showExpressionDialog()
{
//TODO extract this out to a dialog.

QDialog* dlg = new QDialog();
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
Expand All @@ -495,6 +505,8 @@ void QgsLabelingGui::showExpressionDialog()
layout->addWidget(buttonBox);
connect(buttonBox,SIGNAL( accepted() ),dlg,SLOT( accept() ) );
connect(buttonBox,SIGNAL( rejected() ),dlg,SLOT( reject() ) );
QPushButton* okButuon = buttonBox->button(QDialogButtonBox::Ok);
connect(builder, SIGNAL(expressionParsed(bool)), okButuon, SLOT(setEnabled(bool)));

// Set the current expression using the selected text in the combo box.
builder->setExpressionString(this->cboFieldName->currentText());
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsexpressionbuilder.cpp
Expand Up @@ -188,10 +188,14 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
if ( exp.hasParserError())
{
this->txtExpressionString->setStyleSheet("background-color: rgba(255, 6, 10, 75);");
this->txtExpressionString->setToolTip(exp.parserErrorString());
emit expressionParsed(false);
}
else
{
this->txtExpressionString->setStyleSheet("");
this->txtExpressionString->setToolTip("");
emit expressionParsed(true);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/gui/qgsexpressionbuilder.h
Expand Up @@ -78,6 +78,7 @@ class QgsExpressionItem : public QStandardItem
QgsExpressionItem::ItemType mType;
};

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

/** Does the expression used in the widget have any errors */
/** Does the expression used in the widget have any errors
* @note Users of this widget can check this to see if they should let the
* user move forward.
*/
bool hasExpressionError();

public slots:
Expand All @@ -116,6 +120,9 @@ public slots:
void on_expressionTree_doubleClicked(const QModelIndex &index);
void on_txtExpressionString_textChanged();

signals:
void expressionParsed(bool isVaild);

private:
void fillFieldValues(int fieldIndex, int countLimit);

Expand Down
14 changes: 6 additions & 8 deletions src/ui/qgsexpressionbuilder.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>589</width>
<height>604</height>
<width>533</width>
<height>591</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -80,7 +80,7 @@
<item>
<widget class="QLabel" name="mValueListLabel">
<property name="text">
<string>Field Values</string>
<string>&lt;b&gt;Field Values&lt;/b&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -149,8 +149,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>277</width>
<height>140</height>
<width>249</width>
<height>127</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -187,8 +187,6 @@
</widget>
</item>
</layout>
<zorder>txtHelpText</zorder>
<zorder>scrollArea</zorder>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -360,7 +358,7 @@
</size>
</property>
<property name="title">
<string>Expression =</string>
<string>Expression</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
Expand Down
29 changes: 16 additions & 13 deletions src/ui/qgslabelingguibase.ui
Expand Up @@ -79,7 +79,7 @@
</property>
<widget class="QWidget" name="tab_3">
<attribute name="icon">
<iconset>
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
</attribute>
<attribute name="title">
Expand Down Expand Up @@ -390,7 +390,7 @@
</widget>
<widget class="QWidget" name="tab">
<attribute name="icon">
<iconset>
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/general.png</normaloff>:/images/themes/default/propertyicons/general.png</iconset>
</attribute>
<attribute name="title">
Expand Down Expand Up @@ -856,7 +856,7 @@
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="icon">
<iconset>
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/gis/mActionOpenTable.png</normaloff>:/images/themes/gis/mActionOpenTable.png</iconset>
</attribute>
<attribute name="title">
Expand Down Expand Up @@ -1096,6 +1096,9 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -1180,32 +1183,32 @@
<connection>
<sender>chkEnableLabeling</sender>
<signal>clicked(bool)</signal>
<receiver>mTabWidget</receiver>
<receiver>cboFieldName</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>59</x>
<y>22</y>
<x>127</x>
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>91</x>
<y>89</y>
<x>248</x>
<y>26</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkEnableLabeling</sender>
<signal>clicked(bool)</signal>
<receiver>cboFieldName</receiver>
<receiver>mTabWidget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>127</x>
<y>25</y>
<x>59</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>248</x>
<y>26</y>
<x>91</x>
<y>89</y>
</hint>
</hints>
</connection>
Expand Down

0 comments on commit eb0642e

Please sign in to comment.