Skip to content
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

Virtual point clouds - Tile Labels #59726

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Withalion
Copy link
Contributor

Description

In this PR we add the option to show labels when working with virtual point clouds. The labels even if set are only shown when the bounding boxes of point clouds are visible and if they fit inside. Users can also modify the format of the label text via QgsTextFormatButton next to it.

image

Funded by: Klimadatastyrelsen

@github-actions github-actions bot added this to the 3.42.0 milestone Dec 3, 2024
Copy link

github-actions bot commented Dec 3, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 67fc2b9)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 67fc2b9)

* \note This class takes ownership of textFormat
* \since QGIS 3.42
*/
void setLabelTextFormat( QgsTextFormat *textFormat SIP_TRANSFER ) { mLabelTextFormat.reset( textFormat ); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QgsTextFormat is implicitly shared -- it's cheap to make copies of this, so should always be passed/stored by value:

Suggested change
void setLabelTextFormat( QgsTextFormat *textFormat SIP_TRANSFER ) { mLabelTextFormat.reset( textFormat ); }
void setLabelTextFormat( const QgsTextFormat & format ) { mLabelTextFormat = format; }

* \note This function doesn't release the ownership of QgsTextFormat
* \since QGIS 3.42
*/
QgsTextFormat *labelTextFormat() const { return mLabelTextFormat.get(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QgsTextFormat *labelTextFormat() const { return mLabelTextFormat.get(); }
QgsTextFormat labelTextFormat() const { return mLabelTextFormat; }

@@ -813,6 +840,9 @@ class CORE_EXPORT QgsPointCloudRenderer
bool mHorizontalTriangleFilter = false;
double mHorizontalTriangleFilterThreshold = 5.0;
Qgis::RenderUnit mHorizontalTriangleFilterUnit = Qgis::RenderUnit::Millimeters;

bool mShowLabels = false;
std::unique_ptr<QgsTextFormat> mLabelTextFormat = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::unique_ptr<QgsTextFormat> mLabelTextFormat = nullptr;
QgsTextFormat mLabelTextFormat;

Comment on lines +141 to +145
const double textWidth = QgsTextRenderer::textWidth( context.renderContext(), labelTextFormat() ? *labelTextFormat() : QgsTextFormat(), QStringList() << text );
if ( textWidth < extent.width() )
{
QgsTextRenderer::drawText( extent, 0, Qgis::TextHorizontalAlignment::Center, QStringList() << text, context.renderContext(), labelTextFormat() ? *labelTextFormat() : QgsTextFormat(), true, Qgis::TextVerticalAlignment::VerticalCenter );
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little inefficient, because QgsTextRender::textWidth requires parsing the text and determining document metrics and then this will be repeated in ::drawText.

Try the approach used here https://github.com/qgis/QGIS/blob/master/src/app/decorations/qgsdecorationgrid.cpp#L305-L308 and https://github.com/qgis/QGIS/blob/master/src/app/decorations/qgsdecorationgrid.cpp#L374 instead. That will parse the document and calculate metrics once upfront, and then reuse in the drawing.

It's considerably faster this way if you're drawing a lot of text

<item>
<widget class="QCheckBox" name="mLabels">
<property name="text">
<string>Show Tile Labels</string>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkbox text should be sentence case:

Suggested change
<string>Show Tile Labels</string>
<string>Show tile labels</string>

@wonder-sk wonder-sk changed the title Virtual point clouds - Tile Lables Virtual point clouds - Tile Labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants