-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 3 commits
b0b21fe
e04e846
8de102f
e6724fd
49558a0
92e4a46
e3ae420
7ab8214
9fd48a2
9681274
fdbbc99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ SET(QGIS_QUICK_PLUGIN_SRC | |
|
||
SET(QGIS_QUICK_PLUGIN_RESOURCES | ||
qgsquickmapcanvas.qml | ||
qgsquickmessagelog.qml | ||
qgsquickscalebar.qml | ||
qmldir | ||
) | ||
|
||
|
@@ -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 | ||
) | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
) | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document properties (some simple comments what it does if unclear) 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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" ); | ||
|
@@ -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 ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
* | ||
* \since QGIS 3.2 | ||
*/ | ||
class QgsQuickPlugin : public QQmlExtensionPlugin | ||
class QgisQuickPlugin : public QQmlExtensionPlugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QgsQuickPlugin |
||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA( IID "org.qt-project.Qt.QQmlExtensionInterface" ) | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
} |
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QStringLiteral |
||
roles[MessageTagRole] = "MessageTag"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QStringLiteral |
||
roles[MessageLevelRole] = "MessageLevel"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} |
There was a problem hiding this comment.
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?)