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 3 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: 2 additions & 0 deletions doc/qgsquick.dox
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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
\subsubsection qgsquick_overview_widgets_scalebar ScaleBar
\subsubsection qgsquick_overview_widgets_messagelog MessageLog
Copy link
Owner

Choose a reason for hiding this comment

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

when docs are built, does this links to QgsQuickMessageLog class documentation? I am not sure if this was meant to have a short description in each subsection or just a link to the implementation..? (QML + C++ class?)


\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
6 changes: 4 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 @@ -104,7 +106,7 @@ IF(QMLPLUGINDUMP_FOUND)
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 QgisQuick 0.1 . -v --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
Copy link
Owner

Choose a reason for hiding this comment

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

QgsQuick!

Is this building at all? since this probably does not take the correct build directory from the build tree

WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
POST_BUILD
)
Expand Down
71 changes: 71 additions & 0 deletions src/quickgui/plugin/qgsquickmessagelog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/***************************************************************************
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

Item {
property alias model: table.model
Copy link
Owner

Choose a reason for hiding this comment

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

document properties (some simple comments what it does if unclear)
see map canvase.qml for reference

also some simple description what this component does (something like shows all messages from qgsmessagelog ,,,)

property color bgColor: "white"
property color separatorColor: "gray"
property int separatorSize: 1 * QgsQuick.Utils.dp
property bool unreadMessages: false

id: item

Rectangle {
color: item.bgColor
anchors.fill: parent
}

ListView {
id: table
anchors.fill: parent

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

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

Rectangle {
color: item.separatorColor
height: item.separatorSize
width: table.width
}
}
}

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,17 +31,19 @@

#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 )
{
Q_UNUSED( engine )
Q_UNUSED( scriptEngine )
return new QgsQuickUtils(); // the object will be owned by QML engine and destroyed by the engine on exit
return QgsQuickUtils::instance(); // the object will be owned by QML engine and destroyed by the engine on exit
Copy link
Owner

Choose a reason for hiding this comment

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

use version from master

}

void QgsQuickPlugin::registerTypes( const char *uri )
void QgisQuickPlugin::registerTypes( const char *uri )
{
qRegisterMetaType< QList<QgsMapLayer *> >( "QList<QgsMapLayer*>" );
qRegisterMetaType< QgsAttributes > ( "QgsAttributes" );
Expand All @@ -55,6 +57,8 @@ 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 );
Expand Down
2 changes: 1 addition & 1 deletion src/quickgui/plugin/qgsquickplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \since QGIS 3.2
*/
class QgsQuickPlugin : public QQmlExtensionPlugin
class QgisQuickPlugin : public QQmlExtensionPlugin
Copy link
Owner

Choose a reason for hiding this comment

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

QgsQuickPlugin

{
Q_OBJECT
Q_PLUGIN_METADATA( IID "org.qt-project.Qt.QQmlExtensionInterface" )
Expand Down
102 changes: 102 additions & 0 deletions src/quickgui/plugin/qgsquickscalebar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/***************************************************************************
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
Copy link
Owner

Choose a reason for hiding this comment

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

document properties and the component

property alias mapSettings: scaleBarKit.mapSettings
property alias preferredWidth: scaleBarKit.preferredWidth
property QgsQuick.ScaleBarKit scaleBarKit: QgsQuick.ScaleBarKit {id: scaleBarKit}

property int textWidth: fontMetrics.averageCharacterWidth * 8
property color barColor: "white"
property color barBackgroundColor: "grey"
property double barOpacity: 0.8
property string barText: scaleBarKit.distance + " " + scaleBarKit.units
property int barWidth: scaleBarKit.width
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
67 changes: 67 additions & 0 deletions src/quickgui/qgsquickmessagelogmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***************************************************************************
qgsquickmessagelogmodel.cpp
--------------------------------------
date : 13.7.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias (at) opengis.ch
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "qgis.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsapplication.h"

#include "qgsquickmessagelogmodel.h"

QgsQuickMessageLogModel::QgsQuickMessageLogModel( QObject *parent )
: QAbstractListModel( parent )
, mMessageLog( QgsApplication::messageLog() )
{
connect( mMessageLog, static_cast<void ( QgsMessageLog::* )( const QString &message, const QString &tag, Qgis::MessageLevel level )>( &QgsMessageLog::messageReceived ), this, &QgsQuickMessageLogModel::onMessageReceived );
}

QHash<int, QByteArray> QgsQuickMessageLogModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[MessageRole] = "Message";
Copy link
Owner

Choose a reason for hiding this comment

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

QStringLiteral

roles[MessageTagRole] = "MessageTag";
Copy link
Owner

Choose a reason for hiding this comment

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

QStringLiteral

roles[MessageLevelRole] = "MessageLevel";
Copy link
Owner

Choose a reason for hiding this comment

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

QStringLiteral


return roles;
}

int QgsQuickMessageLogModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return mMessages.size();
}

QVariant QgsQuickMessageLogModel::data( const QModelIndex &index, int role ) const
{
if ( index.row() >= mMessages.size() )
return QVariant();

if ( role == MessageRole )
return mMessages.at( index.row() ).message;
else if ( role == MessageTagRole )
return mMessages.at( index.row() ).tag;
else if ( role == MessageLevelRole )
return mMessages.at( index.row() ).level;

return QVariant();
}

void QgsQuickMessageLogModel::onMessageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level )
{
beginInsertRows( QModelIndex(), 0, 0 );
mMessages.prepend( LogMessage( tag, message, level ) );
QgsDebugMsg( QStringLiteral( "Next message %1 : %2" ).arg( tag, message ) );
endInsertRows();
}
Loading