Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[qgsquick] [feature] Added identify and highlight feature
- Loading branch information
1 parent
6002ce0
commit 264788a
Showing
19 changed files
with
1,674 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsquickfeature.cpp | ||
--------------------- | ||
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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsvectorlayer.h" | ||
#include "qgsfeature.h" | ||
|
||
#include "qgsquickfeature.h" | ||
|
||
QgsQuickFeature::QgsQuickFeature( const QgsFeature &feature, QgsVectorLayer *layer ) | ||
: mLayer( layer ) | ||
, mFeature( feature ) | ||
{ | ||
} | ||
|
||
QgsQuickFeature::QgsQuickFeature() | ||
{ | ||
mFeature.setValid( false ); | ||
} | ||
|
||
QgsVectorLayer *QgsQuickFeature::layer() const | ||
{ | ||
return mLayer; | ||
} | ||
|
||
QgsFeature QgsQuickFeature::feature() const | ||
{ | ||
return mFeature; | ||
} | ||
|
||
bool QgsQuickFeature::valid() const | ||
{ | ||
return ( mLayer && mFeature.isValid() ); | ||
} | ||
|
||
void QgsQuickFeature::setFeature( const QgsFeature &feature ) | ||
{ | ||
mFeature = feature; | ||
} | ||
|
||
void QgsQuickFeature::setLayer( QgsVectorLayer *layer ) | ||
{ | ||
mLayer = layer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/*************************************************************************** | ||
qgsquickfeature.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 * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSQUICKFEATURE_H | ||
#define QGSQUICKFEATURE_H | ||
|
||
#include <QObject> | ||
|
||
#include "qgsfeature.h" | ||
|
||
#include "qgis_quick.h" | ||
|
||
class QgsVectorLayer; | ||
|
||
/** | ||
* \ingroup quick | ||
* Pair of QgsFeature and QgsVectorLayer | ||
* | ||
* Vector layer is commonly used to gather geometry type or CRS | ||
* for the feature. | ||
* | ||
* Note that the feature may or may not be part of the vector layer's | ||
* associated features | ||
* | ||
* \note QML Type: QgsQuickFeature | ||
* | ||
* \since QGIS 3.2 | ||
*/ | ||
class QUICK_EXPORT QgsQuickFeature | ||
{ | ||
Q_GADGET | ||
|
||
/** | ||
* Vector layer to which the feature belongs. | ||
* | ||
* This is a readonly property. | ||
*/ | ||
Q_PROPERTY( QgsVectorLayer *layer READ layer ) | ||
|
||
/** | ||
* Feature instance itself. | ||
* | ||
* This is a readonly property. | ||
*/ | ||
Q_PROPERTY( QgsFeature feature READ feature ) | ||
|
||
/** | ||
* Whether the feature is valid and vector layer assigned. | ||
* | ||
* This is a readonly property. | ||
*/ | ||
Q_PROPERTY( bool valid READ valid ) | ||
|
||
public: | ||
//! Constructor of a new feature. | ||
QgsQuickFeature(); | ||
|
||
/** | ||
* Constructor of a new feature. | ||
* \param feature QgsFeature associated. | ||
* \param layer Vector layer which the feature belongs to, if not defined, the feature is not valid. | ||
*/ | ||
QgsQuickFeature( const QgsFeature &feature, | ||
QgsVectorLayer *layer ); | ||
|
||
//! \copydoc QgsQuickFeature::layer | ||
QgsVectorLayer *layer() const; | ||
|
||
//! \copydoc QgsQuickFeature::feature | ||
QgsFeature feature() const; | ||
|
||
//! \copydoc QgsQuickFeature::valid | ||
bool valid() const; | ||
|
||
//! \copydoc QgsQuickFeature::feature | ||
void setFeature( const QgsFeature &feature ); | ||
|
||
//! \copydoc QgsQuickFeature::layer | ||
void setLayer( QgsVectorLayer *layer ); | ||
|
||
private: | ||
QgsVectorLayer *mLayer = nullptr; // not owned | ||
QgsFeature mFeature; | ||
}; | ||
|
||
typedef QList<QgsQuickFeature> QgsQuickFeatureList; | ||
|
||
Q_DECLARE_METATYPE( QgsQuickFeature ) | ||
|
||
#endif // QGSQUICKFEATURE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*************************************************************************** | ||
qgsqguickfeaturehighlight.cpp | ||
-------------------------------------- | ||
Date : 9.12.2014 | ||
Copyright : (C) 2014 by Matthias Kuhn | ||
Email : matthias@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 "qgsvectorlayer.h" | ||
|
||
#include "qgsquickfeaturemodel.h" | ||
#include "qgsquickfeaturehighlight.h" | ||
#include "qgsquickmapsettings.h" | ||
#include "qgsquickhighlightsgnode.h" | ||
|
||
|
||
QgsQuickFeatureHighlight::QgsQuickFeatureHighlight( QQuickItem *parent ) | ||
: QQuickItem( parent ) | ||
{ | ||
setFlags( QQuickItem::ItemHasContents ); | ||
setAntialiasing( true ); | ||
|
||
connect( this, &QgsQuickFeatureHighlight::modelChanged, this, &QgsQuickFeatureHighlight::onDataChanged ); | ||
} | ||
|
||
void QgsQuickFeatureHighlight::onDataChanged() | ||
{ | ||
if ( mModel ) | ||
{ | ||
connect( mModel, &QgsQuickFeatureModel::modelReset, this, &QgsQuickFeatureHighlight::onModelDataChanged ); | ||
connect( mModel, &QgsQuickFeatureModel::rowsRemoved, this, &QgsQuickFeatureHighlight::onModelDataChanged ); | ||
} | ||
|
||
onModelDataChanged(); | ||
} | ||
|
||
void QgsQuickFeatureHighlight::onModelDataChanged() | ||
{ | ||
mDirty = true; | ||
update(); | ||
} | ||
|
||
QSGNode *QgsQuickFeatureHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeData * ) | ||
{ | ||
if ( !mDirty || !mMapSettings ) | ||
return n; | ||
|
||
delete n; | ||
n = new QSGNode; | ||
|
||
if ( !mModel ) | ||
return n; | ||
|
||
QgsVectorLayer *layer = mModel->feature().layer(); | ||
if ( layer ) | ||
{ | ||
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() ); | ||
|
||
QgsFeature feature = mModel->feature().feature(); | ||
QgsGeometry geom( feature.geometry() ); | ||
geom.transform( transf ); | ||
|
||
// TODO: this is very crude conversion! QgsQuickHighlightsNode should accept any type of geometry | ||
QVector<QgsPoint> points; | ||
for ( auto it = geom.vertices_begin(); it != geom.vertices_end(); ++it ) | ||
points.append( *it ); | ||
|
||
QgsQuickHighlightSGNode *rb = new QgsQuickHighlightSGNode( points, geom.type(), mColor, mWidth ); | ||
rb->setFlag( QSGNode::OwnedByParent ); | ||
n->appendChildNode( rb ); | ||
} | ||
mDirty = false; | ||
|
||
return n; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*************************************************************************** | ||
qgsqguickfeaturehighlight.h | ||
-------------------------------------- | ||
Date : 9.12.2014 | ||
Copyright : (C) 2014 by Matthias Kuhn | ||
Email : matthias@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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSQUICKFEATUREHIGHLIGHT_H | ||
#define QGSQUICKFEATUREHIGHLIGHT_H | ||
|
||
#include <QQuickItem> | ||
|
||
#include "qgis_quick.h" | ||
|
||
class QgsQuickMapSettings; | ||
class QgsQuickFeatureModel; | ||
|
||
/** | ||
* \ingroup quick | ||
* | ||
* Creates map highlights for a geometry provided by a FeatureModel. | ||
* | ||
* The highlights are compatible with the QtQuick scene graph. | ||
* | ||
* \note QML Type: FeatureModelHighlight | ||
* | ||
* \since QGIS 3.2 | ||
*/ | ||
class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem | ||
{ | ||
Q_OBJECT | ||
|
||
/** | ||
* Associated map settings. Should be initialized from QML component before the first use. | ||
*/ | ||
Q_PROPERTY( QgsQuickMapSettings *mapSettings MEMBER mMapSettings NOTIFY mapSettingsChanged ) | ||
|
||
/** | ||
* Feature model for geometry. | ||
*/ | ||
Q_PROPERTY( QgsQuickFeatureModel *model MEMBER mModel NOTIFY modelChanged ) | ||
|
||
/** | ||
* Color of the highlighted geometry (feature). | ||
*/ | ||
Q_PROPERTY( QColor color MEMBER mColor NOTIFY colorChanged ) | ||
|
||
/** | ||
* Pen width of the highlighted geometry (feature). Default is 20. | ||
*/ | ||
Q_PROPERTY( unsigned int width MEMBER mWidth NOTIFY widthChanged ) | ||
|
||
public: | ||
//! Creates a new feature highlight | ||
explicit QgsQuickFeatureHighlight( QQuickItem *parent = nullptr ); | ||
|
||
signals: | ||
//! \copydoc QgsQuickFeatureHighlight::model | ||
void modelChanged(); | ||
|
||
//! \copydoc QgsQuickFeatureHighlight::color | ||
void colorChanged(); | ||
|
||
//! \copydoc QgsQuickFeatureHighlight::width | ||
void widthChanged(); | ||
|
||
//! \copydoc QgsQuickFeatureHighlight::mapSettings | ||
void mapSettingsChanged(); | ||
|
||
private slots: | ||
void onDataChanged(); | ||
void onModelDataChanged(); | ||
|
||
private: | ||
QSGNode *updatePaintNode( QSGNode *n, UpdatePaintNodeData * ) override; | ||
|
||
QColor mColor = Qt::yellow; | ||
bool mDirty = false; | ||
unsigned int mWidth = 20; | ||
QgsQuickFeatureModel *mModel = nullptr; // not owned | ||
QgsQuickMapSettings *mMapSettings = nullptr; // not owned | ||
}; | ||
|
||
#endif // QGSQUICKFEATUREHIGHLIGHT_H |
Oops, something went wrong.