Skip to content

Commit

Permalink
Better UX for configuration interface
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 10, 2019
1 parent a761447 commit 013f45e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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() ) );
}
1 change: 1 addition & 0 deletions src/app/qgslabelinggui.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
void updateGeometryTypeBasedWidgets();
void showGeometryGeneratorExpressionBuilder();
void validateGeometryGeneratorExpression();
void determineGeometryGeneratorType();

private:
QgsVectorLayer *mLayer = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions src/ui/qgstextformatwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 013f45e

Please sign in to comment.