Skip to content

Commit

Permalink
Minor fixes (spelling, renaming, sip magic)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Feb 26, 2018
1 parent 8190930 commit bbb2727
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 37 deletions.
18 changes: 12 additions & 6 deletions python/gui/layertree/qgslayertreeview.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/gui/layertree/qgslayertreeviewindicator.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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();

Expand Down
34 changes: 17 additions & 17 deletions src/app/qgslayertreeviewfilterindicator.cpp
@@ -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
***************************************************************************
Expand All @@ -22,7 +22,7 @@
#include "qgsvectorlayer.h"


QgsLayerTreeViewFilterIndicatorManager::QgsLayerTreeViewFilterIndicatorManager( QgsLayerTreeView *view )
QgsLayerTreeViewFilterIndicatorProvider::QgsLayerTreeViewFilterIndicatorProvider( QgsLayerTreeView *view )
: QObject( view )
, mLayerTreeView( view )
{
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 ) )
Expand All @@ -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() )
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgslayertreeviewfilterindicator.h
@@ -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
***************************************************************************
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/gui/layertree/qgslayertreeview.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layertree/qgslayertreeviewindicator.cpp
@@ -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
***************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion src/gui/layertree/qgslayertreeviewindicator.h
@@ -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
***************************************************************************
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/gui/layertree/qgslayertreeviewitemdelegate.cpp
@@ -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
***************************************************************************
Expand All @@ -22,6 +22,7 @@
#include <QHelpEvent>
#include <QToolTip>

/// @cond PRIVATE

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

/// @endcond
6 changes: 5 additions & 1 deletion src/gui/layertree/qgslayertreeviewitemdelegate.h
@@ -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
***************************************************************************
Expand All @@ -16,6 +16,10 @@
#ifndef QGSLAYERTREEVIEWITEMDELEGATE_H
#define QGSLAYERTREEVIEWITEMDELEGATE_H

#include "qgis_sip.h"

SIP_NO_FILE

/// @cond PRIVATE

//
Expand Down

0 comments on commit bbb2727

Please sign in to comment.