Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Proper tooltips for algorithms
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent dab3f51 commit a107e2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -205,6 +205,15 @@ bool QgsProcessingToolboxModel::isTopLevelProvider( QgsProcessingProvider *provi
provider->id() == QLatin1String( "3d" );
}

QString QgsProcessingToolboxModel::toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm )
{
return QStringLiteral( "<p><b>%1</b></p>%2<p>%3</p>" ).arg(
algorithm->displayName(),
!algorithm->shortDescription().isEmpty() ? QStringLiteral( "<p>%1</p>" ).arg( algorithm->shortDescription() ) : QString(),
QObject::tr( "Algorithm ID: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( algorithm->id() ) )
);
}

Qt::ItemFlags QgsProcessingToolboxModel::flags( const QModelIndex &index ) const
{
if ( !index.isValid() )
Expand Down Expand Up @@ -257,7 +266,7 @@ QVariant QgsProcessingToolboxModel::data( const QModelIndex &index, int role ) c
if ( provider )
return provider->longName();
else if ( algorithm )
return algorithm->displayName();
return toolTipForAlgorithm( algorithm );
else if ( groupNode )
return groupNode->name();
else
Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/qgsprocessingtoolboxmodel.h
Expand Up @@ -312,6 +312,11 @@ class GUI_EXPORT QgsProcessingToolboxModel : public QAbstractItemModel
*/
static bool isTopLevelProvider( QgsProcessingProvider *provider );

/**
* Returns a formatted tooltip for an \a algorithm.
*/
static QString toolTipForAlgorithm( const QgsProcessingAlgorithm *algorithm );

};


Expand Down
4 changes: 2 additions & 2 deletions tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -191,15 +191,15 @@ void TestQgsProcessingModel::testModel()
QModelIndex alg1Index = model.index( 0, 0, group1Index );
QVERIFY( !model.providerForIndex( alg1Index ) );
QCOMPARE( model.data( alg1Index, Qt::DisplayRole ).toString(), QStringLiteral( "a1" ) );
QCOMPARE( model.data( alg1Index, Qt::ToolTipRole ).toString(), QStringLiteral( "a1" ) );
QCOMPARE( model.data( alg1Index, Qt::ToolTipRole ).toString(), QStringLiteral( "<p><b>a1</b></p><p>Algorithm ID: \u2018<i>p3:a1</i>\u2019</p>" ) );
QCOMPARE( model.algorithmForIndex( alg1Index )->id(), QStringLiteral( "p3:a1" ) );

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

// combined groups
Expand Down

0 comments on commit a107e2f

Please sign in to comment.