Skip to content
Permalink
Browse files

Minor fixes (spelling, renaming, sip magic)

  • Loading branch information
wonder-sk committed Feb 26, 2018
1 parent 8190930 commit bbb2727bc3bf5795a49bb77644cd4ca96ee56d8d
@@ -118,26 +118,32 @@ in the layer tree view. They can be used to show extra information with tree nod
user interaction.

Does not take ownership of the indicator. One indicator object may be used for multiple layer tree nodes.
\sa removeIndicator
\sa indicators

.. seealso:: :py:func:`removeIndicator`

.. seealso:: :py:func:`indicators`

.. versionadded:: 3.2
%End

void removeIndicator( QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator );
%Docstring
Removes a previously added indicator to a layer tree node. Does not delete the indicator.
\sa addIndicator
\sa indicators

.. seealso:: :py:func:`addIndicator`

.. seealso:: :py:func:`indicators`

.. versionadded:: 3.2
%End

QList<QgsLayerTreeViewIndicator *> indicators( QgsLayerTreeNode *node ) const;
%Docstring
Returns list of indicators associated with a particular layer tree node.
\sa addIndicator
\sa removeIndicator

.. seealso:: :py:func:`addIndicator`

.. seealso:: :py:func:`removeIndicator`

.. versionadded:: 3.2
%End
@@ -26,6 +26,9 @@ and QgsLayerTreeView.removeIndicator() calls.
%End
public:
explicit QgsLayerTreeViewIndicator( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructs an indicator, optionally transferring ownership to a parent QObject
%End

QIcon icon() const;
%Docstring
@@ -3646,7 +3646,7 @@ void QgisApp::initLayerTreeView()

mLayerTreeView->setModel( model );
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider( mLayerTreeView, mMapCanvas ) );
new QgsLayerTreeViewFilterIndicatorManager( mLayerTreeView ); // gets parented to the layer view
new QgsLayerTreeViewFilterIndicatorProvider( mLayerTreeView ); // gets parented to the layer view

setupLayerTreeViewFromSettings();

@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewfilterindicator.cpp
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -22,7 +22,7 @@
#include "qgsvectorlayer.h"


QgsLayerTreeViewFilterIndicatorManager::QgsLayerTreeViewFilterIndicatorManager( QgsLayerTreeView *view )
QgsLayerTreeViewFilterIndicatorProvider::QgsLayerTreeViewFilterIndicatorProvider( QgsLayerTreeView *view )
: QObject( view )
, mLayerTreeView( view )
{
@@ -31,12 +31,12 @@ QgsLayerTreeViewFilterIndicatorManager::QgsLayerTreeViewFilterIndicatorManager(
QgsLayerTree *tree = mLayerTreeView->layerTreeModel()->rootGroup();
onAddedChildren( tree, 0, tree->children().count() - 1 );

connect( tree, &QgsLayerTree::addedChildren, this, &QgsLayerTreeViewFilterIndicatorManager::onAddedChildren );
connect( tree, &QgsLayerTree::willRemoveChildren, this, &QgsLayerTreeViewFilterIndicatorManager::onWillRemoveChildren );
connect( tree, &QgsLayerTree::addedChildren, this, &QgsLayerTreeViewFilterIndicatorProvider::onAddedChildren );
connect( tree, &QgsLayerTree::willRemoveChildren, this, &QgsLayerTreeViewFilterIndicatorProvider::onWillRemoveChildren );
}


void QgsLayerTreeViewFilterIndicatorManager::onAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
void QgsLayerTreeViewFilterIndicatorProvider::onAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
{
// recursively connect to providers' dataChanged() signal

@@ -56,22 +56,22 @@ void QgsLayerTreeViewFilterIndicatorManager::onAddedChildren( QgsLayerTreeNode *
{
if ( vlayer->dataProvider() )
{
connect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorManager::onProviderDataChanged );
connect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorProvider::onProviderDataChanged );

addOrRemoveIndicator( childLayerNode, vlayer->dataProvider() );
}
}
else if ( !childLayerNode->layer() )
{
// wait for layer to be loaded (e.g. when loading project, first the tree is loaded, afterwards the references to layers are resolved)
connect( childLayerNode, &QgsLayerTreeLayer::layerLoaded, this, &QgsLayerTreeViewFilterIndicatorManager::onLayerLoaded );
connect( childLayerNode, &QgsLayerTreeLayer::layerLoaded, this, &QgsLayerTreeViewFilterIndicatorProvider::onLayerLoaded );
}
}
}
}


void QgsLayerTreeViewFilterIndicatorManager::onWillRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
void QgsLayerTreeViewFilterIndicatorProvider::onWillRemoveChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo )
{
// recursively disconnect from providers' dataChanged() signal

@@ -90,14 +90,14 @@ void QgsLayerTreeViewFilterIndicatorManager::onWillRemoveChildren( QgsLayerTreeN
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( childLayerNode->layer() ) )
{
if ( vlayer->dataProvider() )
disconnect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorManager::onProviderDataChanged );
disconnect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorProvider::onProviderDataChanged );
}
}
}
}


void QgsLayerTreeViewFilterIndicatorManager::onLayerLoaded()
void QgsLayerTreeViewFilterIndicatorProvider::onLayerLoaded()
{
QgsLayerTreeLayer *nodeLayer = qobject_cast<QgsLayerTreeLayer *>( sender() );
if ( !nodeLayer )
@@ -107,15 +107,15 @@ void QgsLayerTreeViewFilterIndicatorManager::onLayerLoaded()
{
if ( vlayer->dataProvider() )
{
connect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorManager::onProviderDataChanged );
connect( vlayer->dataProvider(), &QgsDataProvider::dataChanged, this, &QgsLayerTreeViewFilterIndicatorProvider::onProviderDataChanged );

addOrRemoveIndicator( nodeLayer, vlayer->dataProvider() );
}
}
}


void QgsLayerTreeViewFilterIndicatorManager::onProviderDataChanged()
void QgsLayerTreeViewFilterIndicatorProvider::onProviderDataChanged()
{
QgsVectorDataProvider *provider = qobject_cast<QgsVectorDataProvider *>( sender() );
if ( !provider )
@@ -134,7 +134,7 @@ void QgsLayerTreeViewFilterIndicatorManager::onProviderDataChanged()
}


void QgsLayerTreeViewFilterIndicatorManager::onIndicatorClicked( const QModelIndex &index )
void QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked( const QModelIndex &index )
{
QgsLayerTreeNode *node = mLayerTreeView->layerTreeModel()->index2node( index );
if ( !QgsLayerTree::isLayer( node ) )
@@ -151,23 +151,23 @@ void QgsLayerTreeViewFilterIndicatorManager::onIndicatorClicked( const QModelInd
vlayer->dataProvider()->setSubsetString( qb.sql() );
}

QgsLayerTreeViewIndicator *QgsLayerTreeViewFilterIndicatorManager::newIndicator( const QString &filter )
QgsLayerTreeViewIndicator *QgsLayerTreeViewFilterIndicatorProvider::newIndicator( const QString &filter )
{
QgsLayerTreeViewIndicator *indicator = new QgsLayerTreeViewIndicator( this );
indicator->setIcon( mIcon );
updateIndicator( indicator, filter );
connect( indicator, &QgsLayerTreeViewIndicator::clicked, this, &QgsLayerTreeViewFilterIndicatorManager::onIndicatorClicked );
connect( indicator, &QgsLayerTreeViewIndicator::clicked, this, &QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked );
mIndicators.insert( indicator );
return indicator;
}

void QgsLayerTreeViewFilterIndicatorManager::updateIndicator( QgsLayerTreeViewIndicator *indicator, const QString &filter )
void QgsLayerTreeViewFilterIndicatorProvider::updateIndicator( QgsLayerTreeViewIndicator *indicator, const QString &filter )
{
indicator->setToolTip( QString( "<b>%1:</b><br>%2" ).arg( tr( "Filter" ) ).arg( filter ) );
}


void QgsLayerTreeViewFilterIndicatorManager::addOrRemoveIndicator( QgsLayerTreeNode *node, QgsVectorDataProvider *provider )
void QgsLayerTreeViewFilterIndicatorProvider::addOrRemoveIndicator( QgsLayerTreeNode *node, QgsVectorDataProvider *provider )
{
QString filter = provider->subsetString();
if ( !filter.isEmpty() )
@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewfilterindicator.h
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -26,11 +26,11 @@ class QgsVectorDataProvider;


//! Adds indicators showing whether vector layers have a filter applied.
class QgsLayerTreeViewFilterIndicatorManager : public QObject
class QgsLayerTreeViewFilterIndicatorProvider : public QObject
{
Q_OBJECT
public:
explicit QgsLayerTreeViewFilterIndicatorManager( QgsLayerTreeView *view );
explicit QgsLayerTreeViewFilterIndicatorProvider( QgsLayerTreeView *view );

private slots:
//! Connects to signals of layers newly added to the tree
@@ -113,24 +113,24 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
* user interaction.
*
* Does not take ownership of the indicator. One indicator object may be used for multiple layer tree nodes.
* \sa removeIndicator
* \sa indicators
* \see removeIndicator
* \see indicators
* \since QGIS 3.2
*/
void addIndicator( QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator );

/**
* Removes a previously added indicator to a layer tree node. Does not delete the indicator.
* \sa addIndicator
* \sa indicators
* \see addIndicator
* \see indicators
* \since QGIS 3.2
*/
void removeIndicator( QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator );

/**
* Returns list of indicators associated with a particular layer tree node.
* \sa addIndicator
* \sa removeIndicator
* \see addIndicator
* \see removeIndicator
* \since QGIS 3.2
*/
QList<QgsLayerTreeViewIndicator *> indicators( QgsLayerTreeNode *node ) const;
@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewindicator.cpp
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewindicator.h
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -36,6 +36,7 @@ class GUI_EXPORT QgsLayerTreeViewIndicator : public QObject
{
Q_OBJECT
public:
//! Constructs an indicator, optionally transferring ownership to a parent QObject
explicit QgsLayerTreeViewIndicator( QObject *parent SIP_TRANSFERTHIS = nullptr );

//! Indicator icon that will be displayed in the layer tree view
@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewitemdelegate.cpp
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -22,6 +22,7 @@
#include <QHelpEvent>
#include <QToolTip>

/// @cond PRIVATE

QgsLayerTreeViewProxyStyle::QgsLayerTreeViewProxyStyle( QgsLayerTreeView *treeView )
: mLayerTreeView( treeView )
@@ -166,3 +167,5 @@ void QgsLayerTreeViewItemDelegate::onClicked( const QModelIndex &index )
emit indicators[indicatorIndex]->clicked( index );
}
}

/// @endcond
@@ -1,7 +1,7 @@
/***************************************************************************
qgslayertreeviewitemdelegate.h
--------------------------------------
Date : Januray 2018
Date : January 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
@@ -16,6 +16,10 @@
#ifndef QGSLAYERTREEVIEWITEMDELEGATE_H
#define QGSLAYERTREEVIEWITEMDELEGATE_H

#include "qgis_sip.h"

SIP_NO_FILE

/// @cond PRIVATE

//

0 comments on commit bbb2727

Please sign in to comment.
You can’t perform that action at this time.