-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QgsProcessingAlgorithm: add variants of addParameter() and addOutput() that accept a std::unique_ptr #59512
QgsProcessingAlgorithm: add variants of addParameter() and addOutput() that accept a std::unique_ptr #59512
Conversation
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
|
||
// backwards compatibility parameters | ||
// TODO QGIS 4: remove compatibility parameters and their logic | ||
QgsProcessingParameterField *orderField = new QgsProcessingParameterField( QStringLiteral( "ORDER_FIELD" ), | ||
QObject::tr( "Order field" ), QVariant(), QString(), Qgis::ProcessingFieldParameterDataType::Any, false, true ); | ||
auto orderField = std::make_unique<QgsProcessingParameterField>( QStringLiteral( "ORDER_FIELD" ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto orderField = std::make_unique<QgsProcessingParameterField>( QStringLiteral( "ORDER_FIELD" ), | |
std::unique_ptr<QgsProcessingParameterField> orderField = std::make_unique<QgsProcessingParameterField>( QStringLiteral( "ORDER_FIELD" ), |
I don't think we should use auto with these plain and not-that-long type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use auto with these plain and not-that-long type.
oh please please, can't we make an exception here...? I dislike so much reading QGIS code because of all that type boilerplate that brings more noise than value. Here the scope of that variable is so reduced (3 lignes), so that àuto
doesn't hurt. (in my wishlist I would like to kill all those painful explicit QStringLiteral() or QLatin1String() stuff that also make the code hard to read. In an ideal world, the compiler would figure that out itself)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to explicitly describe when we can use auto or not. I was thinking about this comment when I made mine.
But in the end, that's a different scenario. Just a quicklook on stackoverflow and it looks new/make_unique instanciation are also good place to use auto.
So ok then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with auto being used as the type for a std::make_unique call, since it's still immediately clear what the type is when reviewing code.
(That's my big issue with auto -- it makes in-depth reviews impossible to do without first loading the code into an IDE.)
I suggest we need a QEP for this policy, and we could explicitly document where auto should be used vs not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baby steps towards having a place to describe coding policies: qgis/QGIS-Enhancement-Proposals#310
The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check
|
…unique_ptr for QgsProcessingParameterDefinition
…que_ptr for QgsProcessingOutputDefinition
5a1ebdb
to
aff6837
Compare
done |
If we had those 2 new variants and used them, we would have immediately detected the issue fixed by #59511, because the std::move() would have zeroed the smart pointer causing an immediate null-ptr derefrence when later used.
There is no good reason in 2024 to use explicit new and delete :-)