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

Scalebar #3040

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ set(MM_QML
map/MapWrapper.qml
map/MMPositionMarker.qml
map/RecordingTools.qml
map/ScaleBar.qml
map/MMMapScaleBar.qml
map/SplittingTools.qml
map/StakeoutTools.qml
misc/AddPositionProviderPage.qml
Expand Down
13 changes: 7 additions & 6 deletions app/qml/map/MMMapScaleBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import "."
Item {
id: root

property alias mapSettings: scaleBarKit.mapSettings
property alias preferredWidth: scaleBarKit.preferredWidth
// Item to blur (map)
property alias sourceItem: effect.sourceItem
property string text: scaleBarKit.distance + " " + scaleBarKit.units
property real barWidth: scaleBarKit.width

width: root.barWidth + 48 * __dp

ScaleBarKit {
id: scaleBarKit
}

width: scaleBarKit.width + 48 * __dp

Rectangle {
anchors.fill: fastBlur
color: __style.forestColor
Expand All @@ -48,7 +49,7 @@ Item {
}

Column {
width: root.barWidth
width: scaleBarKit.width
anchors.centerIn: parent

Rectangle {
Expand Down Expand Up @@ -83,7 +84,7 @@ Item {
height: 26 * __dp
anchors.horizontalCenter: parent.horizontalCenter

text: root.text
text: scaleBarKit.distance + " " + scaleBarKit.units
color: __style.forestColor
font: __style.t3
horizontalAlignment: Text.AlignHCenter
Expand Down
5 changes: 2 additions & 3 deletions app/qml/map/MapWrapper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@ Item {
visible: mapCanvas.isRendering && root.state !== "inactive"
}

ScaleBar {
MMMapScaleBar {
id: scaleBar

mapSettings: mapCanvas.mapSettings

height: InputStyle.scaleBarHeight
sourceItem: mapCanvas
preferredWidth: Math.min( window.width, 180 * __dp )

anchors.horizontalCenter: parent.horizontalCenter
Expand Down
111 changes: 0 additions & 111 deletions app/qml/map/ScaleBar.qml

This file was deleted.

38 changes: 2 additions & 36 deletions app/scalebarkit.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/***************************************************************************
scalebarkit.h
--------------------------------------
Date : Nov 2017
Copyright : (C) 2017 by Peter Petrik
Email : zilolv at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand All @@ -19,13 +13,11 @@
#include <QObject>
#include <QString>

#include "inputconfig.h"
#include "inpututils.h"
#include "inputmapsettings.h"

/**
*
* \brief The class ScaleBarKit encapsulates the utilities to calculate
* The class ScaleBarKit encapsulates the utilities to calculate
* scale bar properties
*
* It requires connection to mapSettings of the active canvas to automatically
Expand All @@ -37,8 +29,6 @@
*
* System of measurement for result could be set too, so for example the resulting scalebar
* can show results in the imperial units.
*
* \note QML Type: ScaleBarKit
*/
class ScaleBarKit : public QObject
{
Expand Down Expand Up @@ -78,46 +68,23 @@ class ScaleBarKit : public QObject
Q_PROPERTY( int width READ width NOTIFY scaleBarChanged )

public:
//! create new scale bar kit
explicit ScaleBarKit( QObject *parent = nullptr );
~ScaleBarKit() = default;

//! \copydoc ScaleBarKit::mapSettings
void setMapSettings( InputMapSettings *mapSettings );

//! \copydoc ScaleBarKit::width
int width() const;

/**
* \copydoc ScaleBarKit::units
* \see ScaleBarKit::units()
*/
int distance() const;

/**
* \copydoc ScaleBarKit::units
* \see ScaleBarKit::distance()
*/
QString units() const;

signals:

/**
* width, distance and/or units changed
*/
void scaleBarChanged();

//! \copydoc ScaleBarKit::mapSettings
void mapSettingsChanged();

//! \copydoc ScaleBarKit::preferredWidth
void preferredWidthChanged();

//! \copydoc ScaleBarKit::systemOfMeasurement
void systemOfMeasurementChanged();

public slots:
//! recalculate width, distance and units.
//! Recalculate width, distance and units.
void updateScaleBar();

private:
Expand All @@ -129,5 +96,4 @@ class ScaleBarKit : public QObject
Qgis::SystemOfMeasurement mSystemOfMeasurement = Qgis::SystemOfMeasurement::Metric;
};


#endif // SCALEBARKIT_H
11 changes: 7 additions & 4 deletions gallery/qml/pages/MapPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ Page {

MMMapScaleBar {
anchors.horizontalCenter: parent.horizontalCenter
y: 20
y: 120
sourceItem: map
text: Math.floor(map.zoomLevel) + " zoom"
barWidth: map.zoomLevel * 10
onBarWidthChanged: visible = true
preferredWidth: map.zoomLevel * 10
visible: true
onVisibleChanged: {
if (!visible)
visible = true
}
}

MMMapBlurLabel {
Expand Down
15 changes: 15 additions & 0 deletions gallery/scalebarkit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef SCALEBARKIT_H
#define SCALEBARKIT_H

Expand All @@ -12,13 +21,18 @@ class ScaleBarKit : public QObject
Q_PROPERTY( int distance READ distance NOTIFY scaleBarChanged )
Q_PROPERTY( int width READ width NOTIFY scaleBarChanged )

Q_PROPERTY( QString mapSettings MEMBER mMapSettings WRITE setMapSettings NOTIFY scaleBarChanged )
Q_PROPERTY( int preferredWidth MEMBER mPreferredWidth NOTIFY scaleBarChanged )

public:
explicit ScaleBarKit( QObject *parent = nullptr ) {};

int width() const {return mWidth;}
int distance() const {return mDistance;}
QString units() const {return mUnits;}

void setMapSettings( const QString &mapSettings ) {mMapSettings = mapSettings;}

signals:
void scaleBarChanged();

Expand All @@ -28,6 +42,7 @@ class ScaleBarKit : public QObject
int mDistance = 100; // in meters or kilometers, rounded
QString mUnits = "m"; // e.g. km or m

QString mMapSettings;
};

#endif // SCALEBARKIT_H
Loading