Skip to content

Commit

Permalink
rename qgsquickfeature and remove featuremodel
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed May 29, 2018
1 parent 0a99b11 commit 00b6019
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 643 deletions.
6 changes: 2 additions & 4 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
############################################################
# sources
SET(QGIS_QUICK_GUI_MOC_HDRS
qgsquickfeature.h
qgsquickfeaturemodel.h
qgsquickfeaturelayerpair.h
qgsquickfeaturehighlight.h
qgsquickidentifykit.h
qgsquickmapcanvasmap.h
Expand All @@ -18,8 +17,7 @@ SET(QGIS_QUICK_GUI_HDRS
)

SET(QGIS_QUICK_GUI_SRC
qgsquickfeature.cpp
qgsquickfeaturemodel.cpp
qgsquickfeaturelayerpair.cpp
qgsquickfeaturehighlight.cpp
qgsquickhighlightsgnode.cpp
qgsquickidentifykit.cpp
Expand Down
6 changes: 2 additions & 4 deletions src/quickgui/plugin/qgsquickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
#include "qgscoordinatetransformcontext.h"
#include "qgsvectorlayer.h"

#include "qgsquickfeaturemodel.h"
#include "qgsquickfeaturehighlight.h"
#include "qgsquickidentifykit.h"
#include "qgsquickfeature.h"
#include "qgsquickfeaturelayerpair.h"
#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "qgsquickmaptransform.h"
Expand All @@ -58,10 +57,9 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsFeatureId > ( "QgsFeatureId" );
qRegisterMetaType< QgsPoint >( "QgsPoint" );
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeature >( "QgsQuickFeature" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureModel >( uri, 0, 1, "FeatureModel" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
Expand Down
55 changes: 0 additions & 55 deletions src/quickgui/qgsquickfeature.cpp

This file was deleted.

53 changes: 20 additions & 33 deletions src/quickgui/qgsquickfeaturehighlight.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/***************************************************************************
qgsqguickfeaturehighlight.cpp
--------------------------------------
Date : 9.12.2014
Copyright : (C) 2014 by Matthias Kuhn
Email : matthias@opengis.ch
Date : May 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 *
Expand All @@ -17,7 +17,6 @@

#include "qgsvectorlayer.h"

#include "qgsquickfeaturemodel.h"
#include "qgsquickfeaturehighlight.h"
#include "qgsquickmapsettings.h"
#include "qgsquickhighlightsgnode.h"
Expand All @@ -29,52 +28,40 @@ QgsQuickFeatureHighlight::QgsQuickFeatureHighlight( QQuickItem *parent )
setFlags( QQuickItem::ItemHasContents );
setAntialiasing( true );

connect( this, &QgsQuickFeatureHighlight::modelChanged, this, &QgsQuickFeatureHighlight::onDataChanged );
connect( this, &QgsQuickFeatureHighlight::mapSettingsChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::featureLayerPairChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::colorChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::widthChanged, this, &QgsQuickFeatureHighlight::markDirty );
}

void QgsQuickFeatureHighlight::onDataChanged()
{
if ( mModel )
{
connect( mModel, &QgsQuickFeatureModel::modelReset, this, &QgsQuickFeatureHighlight::onModelDataChanged );
connect( mModel, &QgsQuickFeatureModel::rowsRemoved, this, &QgsQuickFeatureHighlight::onModelDataChanged );
}

onModelDataChanged();
}

void QgsQuickFeatureHighlight::onModelDataChanged()
void QgsQuickFeatureHighlight::markDirty()
{
mDirty = true;
update();
}

QSGNode *QgsQuickFeatureHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeData * )
{
if ( !mDirty || !mMapSettings )
if ( !mDirty || !mMapSettings || !mFeatureLayerPair.isValid() )
return n;

delete n;
n = new QSGNode;

if ( !mModel )
return n;
QgsVectorLayer *layer = mFeatureLayerPair.layer();
Q_ASSERT( layer ); // we checked the validity of feature-layer pair
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() );

QgsVectorLayer *layer = mModel->feature().layer();
if ( layer )
QgsFeature feature = mFeatureLayerPair.feature();
if ( feature.hasGeometry() )
{
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() );

QgsFeature feature = mModel->feature().feature();
if ( feature.hasGeometry() )
{
QgsGeometry geom( feature.geometry() );
geom.transform( transf );
std::unique_ptr<QgsQuickHighlightSGNode> rb( new QgsQuickHighlightSGNode( geom, mColor, mWidth ) );
rb->setFlag( QSGNode::OwnedByParent );
n->appendChildNode( rb.release() );
}
QgsGeometry geom( feature.geometry() );
geom.transform( transf );
std::unique_ptr<QgsQuickHighlightSGNode> rb( new QgsQuickHighlightSGNode( geom, mColor, mWidth ) );
rb->setFlag( QSGNode::OwnedByParent );
n->appendChildNode( rb.release() );
}

mDirty = false;

return n;
Expand Down
33 changes: 18 additions & 15 deletions src/quickgui/qgsquickfeaturehighlight.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/***************************************************************************
qgsqguickfeaturehighlight.h
--------------------------------------
Date : 9.12.2014
Copyright : (C) 2014 by Matthias Kuhn
Email : matthias@opengis.ch
---------------------------
Date : May 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 *
Expand All @@ -18,10 +18,10 @@

#include <QQuickItem>

#include "qgsquickfeaturelayerpair.h"
#include "qgis_quick.h"

class QgsQuickMapSettings;
class QgsQuickFeatureModel;

/**
* \ingroup quick
Expand All @@ -44,27 +44,31 @@ class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem
Q_PROPERTY( QgsQuickMapSettings *mapSettings MEMBER mMapSettings NOTIFY mapSettingsChanged )

/**
* Feature model for geometry.
* Feature to highlight
*/
Q_PROPERTY( QgsQuickFeatureModel *model MEMBER mModel NOTIFY modelChanged )
Q_PROPERTY( QgsQuickFeatureLayerPair featureLayerPair MEMBER mFeatureLayerPair NOTIFY featureLayerPairChanged )

/**
* Color of the highlighted geometry (feature).
*
* Default is yellow color
*/
Q_PROPERTY( QColor color MEMBER mColor NOTIFY colorChanged )

/**
* Pen width of the highlighted geometry (feature). Default is 20.
* Pen width of the highlighted geometry (feature).
*
* Default is 20, see QSGGeometry::setLineWidth()
*/
Q_PROPERTY( unsigned int width MEMBER mWidth NOTIFY widthChanged )
Q_PROPERTY( float width MEMBER mWidth NOTIFY widthChanged )

public:
//! Creates a new feature highlight
explicit QgsQuickFeatureHighlight( QQuickItem *parent = nullptr );

signals:
//! \copydoc QgsQuickFeatureHighlight::model
void modelChanged();
//! \copydoc QgsQuickFeatureHighlight::featureLayerPair
void featureLayerPairChanged();

//! \copydoc QgsQuickFeatureHighlight::color
void colorChanged();
Expand All @@ -76,16 +80,15 @@ class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem
void mapSettingsChanged();

private slots:
void onDataChanged();
void onModelDataChanged();
void markDirty();

private:
QSGNode *updatePaintNode( QSGNode *n, UpdatePaintNodeData * ) override;

QColor mColor = Qt::yellow;
bool mDirty = false;
unsigned int mWidth = 20;
QgsQuickFeatureModel *mModel = nullptr; // not owned
float mWidth = 20;
QgsQuickFeatureLayerPair mFeatureLayerPair;
QgsQuickMapSettings *mMapSettings = nullptr; // not owned
};

Expand Down
68 changes: 68 additions & 0 deletions src/quickgui/qgsquickfeaturelayerpair.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************************
qgsquickfeaturelayerpair.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 "qgsquickfeaturelayerpair.h"

QgsQuickFeatureLayerPair::QgsQuickFeatureLayerPair() = default;

QgsQuickFeatureLayerPair::QgsQuickFeatureLayerPair( const QgsFeature &feature, QgsVectorLayer *layer )
: mLayer( layer )
, mFeature( feature )
{
}

QgsVectorLayer *QgsQuickFeatureLayerPair::layer() const
{
return mLayer;
}

QgsFeature QgsQuickFeatureLayerPair::feature() const
{
return mFeature;
}

bool QgsQuickFeatureLayerPair::isValid() const
{
return ( mLayer && mFeature.isValid() && hasValidGeometry() );
}

bool QgsQuickFeatureLayerPair::operator==( const QgsQuickFeatureLayerPair &other ) const
{
return ( mLayer == other.layer() ) && ( mFeature == other.feature() );
}

bool QgsQuickFeatureLayerPair::operator!=( const QgsQuickFeatureLayerPair &other ) const
{
return ( mLayer != other.layer() ) || ( mFeature != other.feature() );
}

bool QgsQuickFeatureLayerPair::hasValidGeometry() const
{
Q_ASSERT( mLayer );

if ( !mFeature.hasGeometry() )
return false;

if ( mFeature.geometry().type() != mLayer->geometryType() )
return false;

if ( QgsWkbTypes::hasZ( mLayer->wkbType() ) != QgsWkbTypes::hasZ( mFeature.geometry().wkbType() ) )
return false;

return true;
}
Loading

0 comments on commit 00b6019

Please sign in to comment.