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

Qgis quick scalebar and logmessage #5

Closed
wants to merge 11 commits into from
Closed
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
9 changes: 9 additions & 0 deletions doc/qgsquick.dox
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha

\subsection qgsquick_overview_widgets QML Classes
\subsubsection qgsquick_overview_widgets_mapcanvas MapCanvas
Similarly to QgsMapCanvas, this component can be used for displaying GIS data on a canvas. See also QgsQuickMapCanvasMap.
\subsubsection qgsquick_overview_widgets_scalebar ScaleBar
A QML component that shows the scale ratio between its length and distance on the MapCanvas. There are predefined rounded values
for several zooming levels with 'm' or 'km' postfixes. After any zoom in/out event on canvas recalculates its properties and updates
text. See also QgsQuickScaleBarKit.

\subsubsection qgsquick_overview_widgets_messagelog MessageLog
A simple panel which can be used for publishing logs messages to a user such as basic information about the application or its status.
See also QgsQuickMessageLogModel.

\section qgsquick_styling Styling

Expand Down
4 changes: 4 additions & 0 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
SET(QGIS_QUICK_GUI_MOC_HDRS
qgsquickmapcanvasmap.h
qgsquickmapsettings.h
qgsquickmessagelogmodel.h
qgsquickscalebarkit.h
qgsquickutils.h
)

Expand All @@ -12,6 +14,8 @@ SET(QGIS_QUICK_GUI_HDRS
SET(QGIS_QUICK_GUI_SRC
qgsquickmapcanvasmap.cpp
qgsquickmapsettings.cpp
qgsquickmessagelogmodel.cpp
qgsquickscalebarkit.cpp
qgsquickutils.cpp
)

Expand Down
7 changes: 5 additions & 2 deletions src/quickgui/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ SET(QGIS_QUICK_PLUGIN_SRC

SET(QGIS_QUICK_PLUGIN_RESOURCES
qgsquickmapcanvas.qml
qgsquickmessagelog.qml
qgsquickscalebar.qml
qmldir
)

Expand All @@ -37,7 +39,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/quickgui

${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/quickgui
)
Expand Down Expand Up @@ -98,13 +100,14 @@ IF(QMLPLUGINDUMP_FOUND)
# Extract QML Types Info from our QML plugin. This is useful for development with Qt Creator as it allows
# Qt Creator understand also the C++ classes registered in the plugin and thus available in QML code
SET(QGIS_QUICK_PLUGIN_TYPEINFO ${QGIS_QUICK_PLUGIN_RUNTIME_DIR}/qgsquick.qmltypes)
SET(QGIS_QUICK_VERSION 0.1)
ADD_CUSTOM_COMMAND(
TARGET qgis_quick_plugin
COMMAND ${CMAKE_COMMAND} -E make_directory ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qgis_quick_plugin> ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${QMLPLUGINDUMP_EXECUTABLE}
ARGS QgsQuick 0.1 . -v --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
ARGS QgsQuick ${QGIS_QUICK_VERSION} . -v --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
POST_BUILD
)
Expand Down
98 changes: 98 additions & 0 deletions src/quickgui/plugin/qgsquickmessagelog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/***************************************************************************
qgsquickmessagelog.qml
--------------------------------------
Date : January 2018
Copyright : (C) 2018 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
import QtQuick.Controls 2.0
import QtQuick 2.5
import QgsQuick 0.1 as QgsQuick


/**
* \brief A component that shows all log messages. The component shows
* the items from QgsQuickMessageLogModel.
*/
Item {
/**
* Input for messages. Must be connected before usage from QgsQuick.MessageLog.
*
* See also QgsQuickMessageLogModel
*/
property alias model: table.model
/**
* Background color
*/
property color bgColor: "white"
/**
* Separator color
*/
property color separatorColor: "gray"

/**
* Separator width
*/
property int separatorSize: 1 * QgsQuick.Utils.dp
/**
* True if there are unread messages in the list. All messages
* are marked read when the widget receives visibility.
*/
property bool unreadMessages: false

id: item

/**
* List containing message logs
*/
ListView {
id: table
anchors.fill: parent

delegate: Column {
Text {
text: MessageTag
font.bold: true
}

Text {
text: Message
width: table.width
wrapMode: Text.WordWrap
}

/**
* Message separator.
*/
Rectangle {
color: item.separatorColor
height: item.separatorSize
width: table.width
}
}
}

/**
* Handles adding new messages to the list.
*/
Connections {
target: model

onRowsInserted: {
if (!visible)
unreadMessages = true
}
}

onVisibleChanged: {
if (visible)
unreadMessages = false
}
}
8 changes: 6 additions & 2 deletions src/quickgui/plugin/qgsquickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "qgsquickmessagelogmodel.h"
#include "qgsquickplugin.h"
#include "qgsquickscalebarkit.h"
#include "qgsquickutils.h"

static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
Expand All @@ -55,11 +57,13 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );

qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );

qmlRegisterUncreatableType< QgsRelationManager >( uri, 0, 1, "RelationManager", "The relation manager is available from the Project. Try `qgisProject.relationManager`" );
qmlRegisterUncreatableType< QgsMessageLog >( uri, 0, 1, "QgsMessageLog", "Expose MessageLevel" );
//qmlRegisterUncreatableType< QgsRelationManager >( uri, 0, 1, "RelationManager", "The relation manager is available from the Project. Try `qgisProject.relationManager`" );
//qmlRegisterUncreatableType< QgsMessageLog >( uri, 0, 1, "QgsMessageLog", "Expose MessageLevel" );
}

141 changes: 141 additions & 0 deletions src/quickgui/plugin/qgsquickscalebar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/***************************************************************************
qgsquickscalebar.qml
--------------------------------------
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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
import QtQuick 2.7
import QtQuick.Controls 2.2
import QgsQuick 0.1 as QgsQuick

Item {
id: scaleBar

/**
* The mapSettings property contains configuration for rendering of the map.
*
* Must be connected before usage from QgsQuick.MapCanvas::mapSettings
*/
property alias mapSettings: scaleBarKit.mapSettings
/**
* Preferred width of scalebar in pixels on the screen. Defaults set to 300.
*
* barWidth is calculated to be close to preferred width, but has "nice" textual
* representation
*/
property alias preferredWidth: scaleBarKit.preferredWidth
/**
* Kit for all calculation of width and text of the scalebar
*
* See also QgsQuickMapCanvasMap::mapSettings
*/
property QgsQuick.ScaleBarKit scaleBarKit: QgsQuick.ScaleBarKit {
id: scaleBarKit
}
/**
* Reserved text width.
*/
property int textWidth: fontMetrics.averageCharacterWidth * 8
/**
* Text color
*/
property color barColor: "white"
/**
* Background color
*/
property color barBackgroundColor: "grey"
/**
* Opacity
*/
property double barOpacity: 0.8
/**
* Textual representation of the bar length (e.g 800 m)
*/
property string barText: scaleBarKit.distance + " " + scaleBarKit.units
/**
* Calculated width of bar in pixels
*/
property int barWidth: scaleBarKit.width
/**
* Size of scalebar line (height of bar)
*/
property int lineWidth: 5 * QgsQuick.Utils.dp

width: textWidth + barWidth

MouseArea {
anchors.fill: background
onClicked: {
animation.restart()
}
}

NumberAnimation {
id: animation
target: scaleBar
property: "barWidth"
to: 200
duration: 1000
}

Rectangle {
id: background
color: scaleBar.barBackgroundColor
opacity: scaleBar.barOpacity
width: parent.width
height: parent.height
}

FontMetrics {
id: fontMetrics
font: text.font
}

Row {
opacity: 1
spacing: 0

Text {
id: text
width: textWidth
height: scaleBar.height
text: barText
color: barColor
font.pixelSize: scaleBar.height - 2 * scaleBar.lineWidth
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}

Rectangle {
id: leftBar
width: scaleBar.lineWidth
height: scaleBar.height - 20 * QgsQuick.Utils.dp
y: (scaleBar.height - leftBar.height) / 2
color: barColor
opacity: 1
}

Rectangle {
width: scaleBar.width - text.width - 15 * QgsQuick.Utils.dp
height: scaleBar.lineWidth
y: (scaleBar.height - scaleBar.lineWidth) / 2
color: barColor
}

Rectangle {
id: rightBar
width: scaleBar.lineWidth
height: scaleBar.height - 20 * QgsQuick.Utils.dp
y: (scaleBar.height - leftBar.height) / 2
color: barColor
}
}
}
2 changes: 2 additions & 0 deletions src/quickgui/plugin/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ module QgsQuick
plugin qgis_quick_plugin

MapCanvas 0.1 qgsquickmapcanvas.qml
ScaleBar 0.1 qgsquickscalebar.qml
MessageLog 0.1 qgsquickmessagelog.qml

typeinfo qgsquick.qmltypes
Loading