Skip to content

Commit a107e2f

Browse files
committedJul 16, 2018
Proper tooltips for algorithms
1 parent dab3f51 commit a107e2f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
 

‎src/gui/processing/qgsprocessingtoolboxmodel.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ bool QgsProcessingToolboxModel::isTopLevelProvider( QgsProcessingProvider *provi
205205
provider->id() == QLatin1String( "3d" );
206206
}
207207

208+
QString QgsProcessingToolboxModel::toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm )
209+
{
210+
return QStringLiteral( "<p><b>%1</b></p>%2<p>%3</p>" ).arg(
211+
algorithm->displayName(),
212+
!algorithm->shortDescription().isEmpty() ? QStringLiteral( "<p>%1</p>" ).arg( algorithm->shortDescription() ) : QString(),
213+
QObject::tr( "Algorithm ID: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( algorithm->id() ) )
214+
);
215+
}
216+
208217
Qt::ItemFlags QgsProcessingToolboxModel::flags( const QModelIndex &index ) const
209218
{
210219
if ( !index.isValid() )
@@ -257,7 +266,7 @@ QVariant QgsProcessingToolboxModel::data( const QModelIndex &index, int role ) c
257266
if ( provider )
258267
return provider->longName();
259268
else if ( algorithm )
260-
return algorithm->displayName();
269+
return toolTipForAlgorithm( algorithm );
261270
else if ( groupNode )
262271
return groupNode->name();
263272
else

‎src/gui/processing/qgsprocessingtoolboxmodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
312312
*/
313313
static bool isTopLevelProvider( QgsProcessingProvider *provider );
314314

315+
/**
316+
* Returns a formatted tooltip for an \a algorithm.
317+
*/
318+
static QString toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm );
319+
315320
};
316321

317322

‎tests/src/gui/testqgsprocessingmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ void TestQgsProcessingModel::testModel()
191191
QModelIndex alg1Index = model.index( 0, 0, group1Index );
192192
QVERIFY( !model.providerForIndex( alg1Index ) );
193193
QCOMPARE( model.data( alg1Index, Qt::DisplayRole ).toString(), QStringLiteral( "a1" ) );
194-
QCOMPARE( model.data( alg1Index, Qt::ToolTipRole ).toString(), QStringLiteral( "a1" ) );
194+
QCOMPARE( model.data( alg1Index, Qt::ToolTipRole ).toString(), QStringLiteral( "<p><b>a1</b></p><p>Algorithm ID: \u2018<i>p3:a1</i>\u2019</p>" ) );
195195
QCOMPARE( model.algorithmForIndex( alg1Index )->id(), QStringLiteral( "p3:a1" ) );
196196

197197
QModelIndex group2Index = model.index( 1, 0, providerIndex );
198198
QCOMPARE( model.rowCount( group2Index ), 1 );
199199
QVERIFY( model.hasChildren( group2Index ) );
200200
QModelIndex alg2Index = model.index( 0, 0, group2Index );
201201
QCOMPARE( model.data( alg2Index, Qt::DisplayRole ).toString(), QStringLiteral( "a2" ) );
202-
QCOMPARE( model.data( alg2Index, Qt::ToolTipRole ).toString(), QStringLiteral( "a2" ) );
202+
QCOMPARE( model.data( alg2Index, Qt::ToolTipRole ).toString(), QStringLiteral( "<p><b>a2</b></p><p>Algorithm ID: \u2018<i>p3:a2</i>\u2019</p>" ) );
203203
QCOMPARE( model.algorithmForIndex( alg2Index )->id(), QStringLiteral( "p3:a2" ) );
204204

205205
// combined groups

0 commit comments

Comments
 (0)
Please sign in to comment.