Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[vectortiles] Show current canvas vector tile zoom level in vector tile
renderer and labeling widgets

Makes it much easier to troubleshoot styles and determine which
rules are currently being applied in the canvas
  • Loading branch information
nyalldawson committed Sep 9, 2020
1 parent 6881946 commit c821288
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp
Expand Up @@ -19,6 +19,8 @@
#include "qgsvectortilelayer.h"

#include "qgslabelinggui.h"
#include "qgsmapcanvas.h"
#include "qgsvectortileutils.h"

#include <QMenu>

Expand Down Expand Up @@ -283,6 +285,7 @@ bool QgsVectorTileBasicLabelingListModel::dropMimeData( const QMimeData *data,

QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )
, mMapCanvas( canvas )
, mMessageBar( messageBar )
{

Expand All @@ -301,6 +304,15 @@ QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTil

connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex );

if ( mMapCanvas )
{
connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
{
mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( QgsVectorTileUtils::scaleToZoomLevel( scale, 0, 99 ) ) );
} );
mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 ) ) );
}

setLayer( layer );
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/vectortile/qgsvectortilebasiclabelingwidget.h
Expand Up @@ -65,6 +65,7 @@ class GUI_EXPORT QgsVectorTileBasicLabelingWidget : public QgsMapLayerConfigWidg
QgsVectorTileLayer *mVTLayer = nullptr;
std::unique_ptr<QgsVectorTileBasicLabeling> mLabeling;
QgsVectorTileBasicLabelingListModel *mModel = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;
};

Expand Down
12 changes: 12 additions & 0 deletions src/gui/vectortile/qgsvectortilebasicrendererwidget.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgsvectortilelayer.h"
#include "qgssymbolselectordialog.h"
#include "qgsstyle.h"
#include "qgsmapcanvas.h"
#include "qgsvectortileutils.h"

#include <QAbstractListModel>
#include <QInputDialog>
Expand Down Expand Up @@ -298,6 +300,7 @@ bool QgsVectorTileBasicRendererListModel::dropMimeData( const QMimeData *data,

QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTileLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )
, mMapCanvas( canvas )
, mMessageBar( messageBar )
{
setupUi( this );
Expand All @@ -314,6 +317,15 @@ QgsVectorTileBasicRendererWidget::QgsVectorTileBasicRendererWidget( QgsVectorTil

connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicRendererWidget::editStyleAtIndex );

if ( mMapCanvas )
{
connect( mMapCanvas, &QgsMapCanvas::scaleChanged, this, [ = ]( double scale )
{
mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( QgsVectorTileUtils::scaleToZoomLevel( scale, 0, 99 ) ) );
} );
mLabelCurrentZoom->setText( tr( "Current zoom: %1" ).arg( QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 ) ) );
}

setLayer( layer );
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/vectortile/qgsvectortilebasicrendererwidget.h
Expand Up @@ -65,6 +65,7 @@ class GUI_EXPORT QgsVectorTileBasicRendererWidget : public QgsMapLayerConfigWidg
QgsVectorTileLayer *mVTLayer = nullptr;
std::unique_ptr<QgsVectorTileBasicRenderer> mRenderer;
QgsVectorTileBasicRendererListModel *mModel = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;
};

Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsvectortilebasiclabelingwidget.ui
Expand Up @@ -93,6 +93,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="mLabelCurrentZoom">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsvectortilebasicrendererwidget.ui
Expand Up @@ -93,6 +93,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="mLabelCurrentZoom">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit c821288

Please sign in to comment.