From 8ceaf00f98b89082e775546ec7e7c73dcd6bd379 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 28 Feb 2022 14:15:11 +1000 Subject: [PATCH] Show more detailed help for models in qgis_process Include any examples, author and version information in help output --- src/process/qgsprocess.cpp | 36 ++++++++++++++++--- tests/src/python/test_qgsprocessexecutable.py | 4 +++ tests/testdata/test_model.model3 | 12 ++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/process/qgsprocess.cpp b/src/process/qgsprocess.cpp index 249e9f8cf71..73cb75a28f0 100644 --- a/src/process/qgsprocess.cpp +++ b/src/process/qgsprocess.cpp @@ -805,13 +805,41 @@ int QgsProcessingExec::showAlgorithmHelp( const QString &inputId, bool useJson ) if ( !useJson ) { std::cout << QStringLiteral( "%1 (%2)\n" ).arg( alg->displayName(), alg->id() ).toLocal8Bit().constData(); + std::cout << "\n----------------\n"; std::cout << "Description\n"; std::cout << "----------------\n"; - if ( !alg->shortDescription().isEmpty() ) - std::cout << alg->shortDescription().toLocal8Bit().constData() << '\n'; - if ( !alg->shortHelpString().isEmpty() && alg->shortHelpString() != alg->shortDescription() ) - std::cout << alg->shortHelpString().toLocal8Bit().constData() << '\n'; + + if ( const QgsProcessingModelAlgorithm *model = dynamic_cast< const QgsProcessingModelAlgorithm * >( alg ) ) + { + // show finer help content for models + const QVariantMap help = model->helpContent(); + std::cout << help.value( QStringLiteral( "ALG_DESC" ) ).toString().toLocal8Bit().constData() << '\n'; + + if ( !help.value( QStringLiteral( "ALG_CREATOR" ) ).toString().isEmpty() || + !help.value( QStringLiteral( "ALG_VERSION" ) ).toString().isEmpty() ) + std::cout << '\n'; + + if ( !help.value( QStringLiteral( "ALG_CREATOR" ) ).toString().isEmpty() ) + std::cout << "Algorithm author:\t" << help.value( QStringLiteral( "ALG_CREATOR" ) ).toString().toLocal8Bit().constData() << '\n'; + if ( !help.value( QStringLiteral( "ALG_VERSION" ) ).toString().isEmpty() ) + std::cout << "Algorithm version:\t" << help.value( QStringLiteral( "ALG_VERSION" ) ).toString().toLocal8Bit().constData() << '\n'; + + if ( !help.value( QStringLiteral( "EXAMPLES" ) ).toString().isEmpty() ) + { + std::cout << "\n----------------\n"; + std::cout << "Examples\n"; + std::cout << "----------------\n"; + std::cout << help.value( QStringLiteral( "EXAMPLES" ) ).toString().toLocal8Bit().constData() << '\n'; + } + } + else + { + if ( !alg->shortDescription().isEmpty() ) + std::cout << alg->shortDescription().toLocal8Bit().constData() << '\n'; + if ( !alg->shortHelpString().isEmpty() && alg->shortHelpString() != alg->shortDescription() ) + std::cout << alg->shortHelpString().toLocal8Bit().constData() << '\n'; + } std::cout << "\n----------------\n"; std::cout << "Arguments\n"; diff --git a/tests/src/python/test_qgsprocessexecutable.py b/tests/src/python/test_qgsprocessexecutable.py index 305898406bf..ab153e5abdc 100644 --- a/tests/src/python/test_qgsprocessexecutable.py +++ b/tests/src/python/test_qgsprocessexecutable.py @@ -402,6 +402,10 @@ class TestQgsProcessExecutable(unittest.TestCase): self.assertFalse(err) self.assertEqual(rc, 0) self.assertIn('model description', output.lower()) + self.assertIn('author of model', output.lower()) + self.assertIn('version 2.1', output.lower()) + self.assertIn('examples', output.lower()) + self.assertIn('this is an example of running the model', output.lower()) def testModelRun(self): output_file = self.TMP_DIR + '/model_output.shp' diff --git a/tests/testdata/test_model.model3 b/tests/testdata/test_model.model3 index 156446bf8e0..1e1722ac263 100644 --- a/tests/testdata/test_model.model3 +++ b/tests/testdata/test_model.model3 @@ -71,7 +71,12 @@ +