Skip to content

Commit 9a79fc7

Browse files
authored
Merge pull request #6983 from PeterPetrik/qgsquick_2_scalebar_messagelog
[feature] Add ScaleBar and MessageLog components to QgsQuick library.
2 parents fe93993 + 0cd9e19 commit 9a79fc7

17 files changed

Lines changed: 803 additions & 9 deletions

‎doc/qgsquick.dox‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha
1313

1414
\subsection qgsquick_overview_widgets QML Classes
1515
\subsubsection qgsquick_overview_widgets_mapcanvas MapCanvas
16+
Similarly to QgsMapCanvas, this component can be used for displaying GIS data on a canvas. See also QgsQuickMapCanvasMap.
17+
\subsubsection qgsquick_overview_widgets_scalebar ScaleBar
18+
A QML component that shows the scale ratio between its length and distance on the MapCanvas. There are predefined rounded values
19+
for several zooming levels with 'm' or 'km' postfixes. After any zoom in/out event on canvas recalculates its properties and updates
20+
text. See also QgsQuickScaleBarKit.
21+
22+
\subsubsection qgsquick_overview_widgets_messagelog MessageLog
23+
A simple panel which can be used for publishing logs messages to a user such as basic information about the application or its status.
24+
See also QgsQuickMessageLogModel.
1625

1726
\section qgsquick_styling Styling
1827

‎src/quickgui/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
SET(QGIS_QUICK_GUI_MOC_HDRS
44
qgsquickmapcanvasmap.h
55
qgsquickmapsettings.h
6+
qgsquickmessagelogmodel.h
7+
qgsquickscalebarkit.h
68
qgsquickutils.h
79
)
810

@@ -12,6 +14,8 @@ SET(QGIS_QUICK_GUI_HDRS
1214
SET(QGIS_QUICK_GUI_SRC
1315
qgsquickmapcanvasmap.cpp
1416
qgsquickmapsettings.cpp
17+
qgsquickmessagelogmodel.cpp
18+
qgsquickscalebarkit.cpp
1519
qgsquickutils.cpp
1620
)
1721

‎src/quickgui/plugin/CMakeLists.txt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ SET(QGIS_QUICK_PLUGIN_SRC
1111

1212
SET(QGIS_QUICK_PLUGIN_RESOURCES
1313
qgsquickmapcanvas.qml
14+
qgsquickmessagelog.qml
15+
qgsquickscalebar.qml
1416
qmldir
1517
)
1618

@@ -37,7 +39,7 @@ INCLUDE_DIRECTORIES(
3739
${CMAKE_SOURCE_DIR}/src/core/metadata
3840
${CMAKE_SOURCE_DIR}/src/core/expression
3941
${CMAKE_SOURCE_DIR}/src/quickgui
40-
42+
4143
${CMAKE_BINARY_DIR}/src/core
4244
${CMAKE_BINARY_DIR}/src/quickgui
4345
)
@@ -99,13 +101,14 @@ IF(QMLPLUGINDUMP_FOUND)
99101
# Qt Creator understand also the C++ classes registered in the plugin and thus available in QML code
100102
# If the qmlplugindumpcommand fails, add -v argument to see detailed output for debugging
101103
SET(QGIS_QUICK_PLUGIN_TYPEINFO ${QGIS_QUICK_PLUGIN_RUNTIME_DIR}/qgsquick.qmltypes)
104+
SET(QGIS_QUICK_VERSION 0.1)
102105
ADD_CUSTOM_COMMAND(
103106
TARGET qgis_quick_plugin
104107
COMMAND ${CMAKE_COMMAND} -E make_directory ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
105108
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
106109
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qgis_quick_plugin> ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
107110
COMMAND ${QMLPLUGINDUMP_EXECUTABLE}
108-
ARGS QgsQuick 0.1 . --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
111+
ARGS QgsQuick ${QGIS_QUICK_VERSION} . --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
109112
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
110113
POST_BUILD
111114
)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/***************************************************************************
2+
qgsquickmessagelog.qml
3+
--------------------------------------
4+
Date : January 2018
5+
Copyright : (C) 2018 by Peter Petrik
6+
Email : zilolv at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
import QtQuick.Controls 2.0
16+
import QtQuick 2.5
17+
import QgsQuick 0.1 as QgsQuick
18+
19+
20+
/**
21+
* \brief A component that shows all log messages. The component shows
22+
* the items from QgsQuickMessageLogModel.
23+
*/
24+
Item {
25+
/**
26+
* Input for messages. Must be connected before usage from QgsQuick.MessageLog.
27+
*
28+
* See also QgsQuickMessageLogModel
29+
*/
30+
property alias model: table.model
31+
/**
32+
* Background color
33+
*/
34+
property color bgColor: "white"
35+
/**
36+
* Separator color
37+
*/
38+
property color separatorColor: "gray"
39+
40+
/**
41+
* Separator width
42+
*/
43+
property int separatorSize: 1 * QgsQuick.Utils.dp
44+
/**
45+
* True if there are unread messages in the list. All messages
46+
* are marked read when the widget receives visibility.
47+
*/
48+
property bool unreadMessages: false
49+
50+
id: item
51+
52+
/**
53+
* List containing message logs
54+
*/
55+
ListView {
56+
id: table
57+
anchors.fill: parent
58+
59+
delegate: Column {
60+
Text {
61+
text: MessageTag
62+
font.bold: true
63+
}
64+
65+
Text {
66+
text: Message
67+
width: table.width
68+
wrapMode: Text.WordWrap
69+
}
70+
71+
/**
72+
* Message separator.
73+
*/
74+
Rectangle {
75+
color: item.separatorColor
76+
height: item.separatorSize
77+
width: table.width
78+
}
79+
}
80+
}
81+
82+
/**
83+
* Handles adding new messages to the list.
84+
*/
85+
Connections {
86+
target: model
87+
88+
onRowsInserted: {
89+
if (!visible)
90+
unreadMessages = true
91+
}
92+
}
93+
94+
onVisibleChanged: {
95+
if (visible)
96+
unreadMessages = false
97+
}
98+
}

‎src/quickgui/plugin/qgsquickplugin.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#include "qgsquickmapcanvasmap.h"
3333
#include "qgsquickmapsettings.h"
34+
#include "qgsquickmessagelogmodel.h"
3435
#include "qgsquickplugin.h"
36+
#include "qgsquickscalebarkit.h"
3537
#include "qgsquickutils.h"
3638

3739
static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
@@ -55,11 +57,10 @@ void QgsQuickPlugin::registerTypes( const char *uri )
5557
qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
5658
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
5759
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
60+
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
61+
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
5862
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
5963

6064
qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );
61-
62-
qmlRegisterUncreatableType< QgsRelationManager >( uri, 0, 1, "RelationManager", "The relation manager is available from the Project. Try `qgisProject.relationManager`" );
63-
qmlRegisterUncreatableType< QgsMessageLog >( uri, 0, 1, "QgsMessageLog", "Expose MessageLevel" );
6465
}
6566

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/***************************************************************************
2+
qgsquickscalebar.qml
3+
--------------------------------------
4+
Date : Nov 2017
5+
Copyright : (C) 2017 by Peter Petrik
6+
Email : zilolv at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
import QtQuick 2.7
16+
import QtQuick.Controls 2.2
17+
import QgsQuick 0.1 as QgsQuick
18+
19+
Item {
20+
id: scaleBar
21+
22+
/**
23+
* The mapSettings property contains configuration for rendering of the map.
24+
*
25+
* Must be connected before usage from QgsQuick.MapCanvas::mapSettings
26+
*/
27+
property alias mapSettings: scaleBarKit.mapSettings
28+
/**
29+
* Preferred width of scalebar in pixels on the screen. Defaults set to 300.
30+
*
31+
* barWidth is calculated to be close to preferred width, but has "nice" textual
32+
* representation
33+
*/
34+
property alias preferredWidth: scaleBarKit.preferredWidth
35+
/**
36+
* Kit for all calculation of width and text of the scalebar
37+
*
38+
* See also QgsQuickMapCanvasMap::mapSettings
39+
*/
40+
property QgsQuick.ScaleBarKit scaleBarKit: QgsQuick.ScaleBarKit {
41+
id: scaleBarKit
42+
}
43+
/**
44+
* Reserved text width.
45+
*/
46+
property int textWidth: fontMetrics.averageCharacterWidth * 8
47+
/**
48+
* Text color
49+
*/
50+
property color barColor: "white"
51+
/**
52+
* Background color
53+
*/
54+
property color barBackgroundColor: "grey"
55+
/**
56+
* Opacity
57+
*/
58+
property double barOpacity: 0.8
59+
/**
60+
* Textual representation of the bar length (e.g 800 m)
61+
*/
62+
property string barText: scaleBarKit.distance + " " + scaleBarKit.units
63+
/**
64+
* Calculated width of bar in pixels
65+
*/
66+
property int barWidth: scaleBarKit.width
67+
/**
68+
* Size of scalebar line (height of bar)
69+
*/
70+
property int lineWidth: 5 * QgsQuick.Utils.dp
71+
72+
width: textWidth + barWidth
73+
74+
MouseArea {
75+
anchors.fill: background
76+
onClicked: {
77+
animation.restart()
78+
}
79+
}
80+
81+
NumberAnimation {
82+
id: animation
83+
target: scaleBar
84+
property: "barWidth"
85+
to: 200
86+
duration: 1000
87+
}
88+
89+
Rectangle {
90+
id: background
91+
color: scaleBar.barBackgroundColor
92+
opacity: scaleBar.barOpacity
93+
width: parent.width
94+
height: parent.height
95+
}
96+
97+
FontMetrics {
98+
id: fontMetrics
99+
font: text.font
100+
}
101+
102+
Row {
103+
opacity: 1
104+
spacing: 0
105+
106+
Text {
107+
id: text
108+
width: textWidth
109+
height: scaleBar.height
110+
text: barText
111+
color: barColor
112+
font.pixelSize: scaleBar.height - 2 * scaleBar.lineWidth
113+
horizontalAlignment: Text.AlignHCenter
114+
verticalAlignment: Text.AlignVCenter
115+
}
116+
117+
Rectangle {
118+
id: leftBar
119+
width: scaleBar.lineWidth
120+
height: scaleBar.height - 20 * QgsQuick.Utils.dp
121+
y: (scaleBar.height - leftBar.height) / 2
122+
color: barColor
123+
opacity: 1
124+
}
125+
126+
Rectangle {
127+
width: scaleBar.width - text.width - 15 * QgsQuick.Utils.dp
128+
height: scaleBar.lineWidth
129+
y: (scaleBar.height - scaleBar.lineWidth) / 2
130+
color: barColor
131+
}
132+
133+
Rectangle {
134+
id: rightBar
135+
width: scaleBar.lineWidth
136+
height: scaleBar.height - 20 * QgsQuick.Utils.dp
137+
y: (scaleBar.height - leftBar.height) / 2
138+
color: barColor
139+
}
140+
}
141+
}

‎src/quickgui/plugin/qmldir‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ module QgsQuick
1414
plugin qgis_quick_plugin
1515

1616
MapCanvas 0.1 qgsquickmapcanvas.qml
17+
ScaleBar 0.1 qgsquickscalebar.qml
18+
MessageLog 0.1 qgsquickmessagelog.qml
1719

1820
typeinfo qgsquick.qmltypes

0 commit comments

Comments
 (0)