Skip to content
Permalink
Browse files

Proper tooltips for algorithms

  • Loading branch information
nyalldawson committed Jul 2, 2018
1 parent dab3f51 commit a107e2fd0b359d0e7acdaff9ad2bb2b6a6a1d1ea
@@ -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() )
@@ -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
@@ -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 );

};


@@ -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

0 comments on commit a107e2f

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