Skip to content
Permalink
Browse files

Better UX for configuration interface

  • Loading branch information
m-kuhn committed Mar 10, 2019
1 parent a761447 commit 013f45e0f024034ca31ab873d1aa807480389445
Showing with 34 additions and 1 deletion.
  1. +24 −1 src/app/qgslabelinggui.cpp
  2. +1 −0 src/app/qgslabelinggui.h
  3. +9 −0 src/ui/qgstextformatwidgetbase.ui
@@ -94,6 +94,12 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas,
mMaxScaleWidget->setShowCurrentScaleButton( true );

mGeometryGeneratorWarningLabel->setStyleSheet( QStringLiteral( "color: #FFC107;" ) );
mGeometryGeneratorWarningLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
connect( mGeometryGeneratorWarningLabel, &QLabel::linkActivated, this, [this]( const QString & link )
{
if ( link == QLatin1String( "#determineGeometryGeneratorType" ) )
determineGeometryGeneratorType();
} );

setLayer( layer );
}
@@ -748,11 +754,28 @@ void QgsLabelingGui::validateGeometryGeneratorExpression()
}
else if ( geometry.type() != configuredGeometryType )
{
mGeometryGeneratorWarningLabel->setText( tr( "Result of the expression does not match configured geometry type. Result is %1, Configured %2." ).arg( QgsWkbTypes::geometryDisplayString( geometry.type() ), QgsWkbTypes::geometryDisplayString( configuredGeometryType ) ) );
mGeometryGeneratorWarningLabel->setText( QStringLiteral( "<p>%1</p><p><a href=\"#determineGeometryGeneratorType\">%2</a></p>" ).arg(
tr( "Result of the expression does not match configured geometry type." ),
tr( "Fix it" ) ) );
valid = false;
}
}
}

mGeometryGeneratorWarningLabel->setVisible( !valid );
}

void QgsLabelingGui::determineGeometryGeneratorType()
{
if ( !mPreviewFeature.isValid() && mLayer )
mLayer->getFeatures( QgsFeatureRequest().setLimit( 1 ) ).nextFeature( mPreviewFeature );

QgsExpression expression( mGeometryGenerator->text() );
QgsExpressionContext context = createExpressionContext();
context.setFeature( mPreviewFeature );

expression.prepare( &context );
const QgsGeometry geometry = expression.evaluate( &context ).value<QgsGeometry>();

mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( geometry.type() ) );
}
@@ -77,6 +77,7 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
void updateGeometryTypeBasedWidgets();
void showGeometryGeneratorExpressionBuilder();
void validateGeometryGeneratorExpression();
void determineGeometryGeneratorType();

private:
QgsVectorLayer *mLayer = nullptr;
@@ -4993,13 +4993,22 @@ font-style: italic;</string>
</item>
<item>
<widget class="QGroupBox" name="mGeometryGeneratorGroupBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Generates or transforms the geometry to be used for labeling&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;The expression will be applied to each feature while rendering and the label will be placed based on the expression result.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="title">
<string>Geometry generator</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_41">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item row="1" column="0" rowspan="2">
<widget class="QgsCodeEditorExpression" name="mGeometryGenerator" native="true"/>
</item>

0 comments on commit 013f45e

Please sign in to comment.
You can’t perform that action at this time.