Skip to content
Permalink
Browse files

Added python bindings

  • Loading branch information
wonder-sk committed Jun 2, 2016
1 parent ea58024 commit 301fd985af69e200bd2be30c1fc3481f0d2487ba
@@ -192,6 +192,8 @@
%Include auth/qgsauthtrustedcasdialog.sip

%Include layertree/qgscustomlayerorderwidget.sip
%Include layertree/qgslayertreeembeddedconfigwidget.sip
%Include layertree/qgslayertreeembeddedwidgetregistry.sip
%Include layertree/qgslayertreemapcanvasbridge.sip
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip
@@ -0,0 +1,22 @@

/** \ingroup gui
* \class QgsLayerTreeEmbeddedConfigWidget
* A widget to configure layer tree embedded widgets for a particular map layer.
* @note introduced in QGIS 2.16
*/
class QgsLayerTreeEmbeddedConfigWidget : public QWidget
{
%TypeHeaderCode
#include <qgslayertreeembeddedconfigwidget.h>
%End

public:
QgsLayerTreeEmbeddedConfigWidget( QWidget* parent /TransferThis/ = nullptr );

//! Initialize widget with a map layer
void setLayer( QgsMapLayer* layer );

//! Store changes made in the widget to the layer
void applyToLayer();

};
@@ -0,0 +1,72 @@

/** \ingroup gui
* \class QgsLayerTreeEmbeddedWidgetProvider
* Provider interface to be implemented in order to introduce new kinds of embedded widgets for use in layer tree.
* Embedded widgets are assigned per individual map layers and they are shown before any legend entries.
* @see QgsLayerTreeEmbeddedWidgetRegistry
* @note introduced in QGIS 2.16
*/
class QgsLayerTreeEmbeddedWidgetProvider
{
%TypeHeaderCode
#include <qgslayertreeembeddedwidgetregistry.h>
%End

public:
virtual ~QgsLayerTreeEmbeddedWidgetProvider();

//! Unique name of the provider (among other providers)
virtual QString id() const = 0;

//! Human readable name - may be translatable with tr()
virtual QString name() const = 0;

//! Factory to create widgets. The returned widget is owned by the caller.
//! The widgetIndex argument may be used to identify which widget is being
//! created (useful when using multiple widgets from the same provider for one layer).
virtual QWidget* createWidget( QgsMapLayer* layer, int widgetIndex ) = 0 /Factory/;

//! Whether it makes sense to use this widget for a particular layer
virtual bool supportsLayer( QgsMapLayer* layer ) = 0;
};

/** \ingroup gui
* \class QgsLayerTreeEmbeddedWidgetRegistry
* Registry of widgets that may be embedded into layer tree view.
* Embedded widgets are assigned per individual map layers and they are shown before any legend entries.
* Layer tree must have UseEmbeddedWidgets flag enabled in order to show assigned widgets.
*
* @see QgsLayerTreeEmbeddedWidgetRegistry
* @note introduced in QGIS 2.16
*/
class QgsLayerTreeEmbeddedWidgetRegistry
{
%TypeHeaderCode
#include <qgslayertreeembeddedwidgetregistry.h>
%End

public:

/** Means of accessing canonical single instance */
static QgsLayerTreeEmbeddedWidgetRegistry* instance();

~QgsLayerTreeEmbeddedWidgetRegistry();

/** Return list of all registered providers */
QStringList providers() const;

/** Get provider object from the provider's ID */
QgsLayerTreeEmbeddedWidgetProvider* provider( const QString& providerId ) const;

/** Register a provider, takes ownership of the object.
* Returns true on success, false if the provider is already registered. */
bool addProvider( QgsLayerTreeEmbeddedWidgetProvider* provider /Transfer/ );

/** Unregister a provider, the provider object is deleted.
* Returns true on success, false if the provider was not registered. */
bool removeProvider( const QString& providerId );

protected:
//! Protected constructor - use instance() to access the registry.
QgsLayerTreeEmbeddedWidgetRegistry();
};
@@ -1,3 +1,18 @@
/***************************************************************************
qgslayertreeembeddedconfigwidget.cpp
--------------------------------------
Date : May 2016
Copyright : (C) 2016 by Martin Dobias
Email : wonder dot sk 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 "qgslayertreeembeddedconfigwidget.h"

#include "qgsmaplayer.h"
@@ -1,3 +1,18 @@
/***************************************************************************
qgslayertreeembeddedconfigwidget.h
--------------------------------------
Date : May 2016
Copyright : (C) 2016 by Martin Dobias
Email : wonder dot sk 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 QGSLAYERTREEEMBEDDEDCONFIGWIDGET_H
#define QGSLAYERTREEEMBEDDEDCONFIGWIDGET_H

@@ -34,18 +34,19 @@ class GUI_EXPORT QgsLayerTreeEmbeddedWidgetProvider
public:
virtual ~QgsLayerTreeEmbeddedWidgetProvider() {}

//! unique name of the provider (among other providers)
//! Unique name of the provider (among other providers)
virtual QString id() const = 0;

//! human readable name - may be translatable with tr()
//! Human readable name - may be translatable with tr()
virtual QString name() const = 0;

//! factory to create widgets
virtual QWidget* createWidget( QgsMapLayer* layer, QMap<QString, QString> properties ) = 0;
//! Factory to create widgets. The returned widget is owned by the caller.
//! The widgetIndex argument may be used to identify which widget is being
//! created (useful when using multiple widgets from the same provider for one layer).
virtual QWidget* createWidget( QgsMapLayer* layer, int widgetIndex ) = 0;

//! whether it makes sense to use this widget for a particular layer
//! Whether it makes sense to use this widget for a particular layer
virtual bool supportsLayer( QgsMapLayer* layer ) = 0;

};

/** \ingroup gui
@@ -88,16 +88,16 @@ QString QgsLayerTreeTransparencyWidget::Provider::id() const

QString QgsLayerTreeTransparencyWidget::Provider::name() const
{
return tr("Transparency slider");
return tr( "Transparency slider" );
}

QgsLayerTreeTransparencyWidget* QgsLayerTreeTransparencyWidget::Provider::createWidget(QgsMapLayer* layer, QMap<QString, QString> properties)
QgsLayerTreeTransparencyWidget* QgsLayerTreeTransparencyWidget::Provider::createWidget( QgsMapLayer* layer, int widgetIndex )
{
Q_UNUSED( properties );
Q_UNUSED( widgetIndex );
return new QgsLayerTreeTransparencyWidget( layer );
}

bool QgsLayerTreeTransparencyWidget::Provider::supportsLayer(QgsMapLayer* layer)
bool QgsLayerTreeTransparencyWidget::Provider::supportsLayer( QgsMapLayer* layer )
{
return layer->type() == QgsMapLayer::VectorLayer || layer->type() == QgsMapLayer::RasterLayer;
}
@@ -41,7 +41,7 @@ class QgsLayerTreeTransparencyWidget : public QWidget
public:
virtual QString id() const override;
virtual QString name() const override;
virtual QgsLayerTreeTransparencyWidget* createWidget( QgsMapLayer* layer, QMap<QString, QString> properties ) override;
virtual QgsLayerTreeTransparencyWidget* createWidget( QgsMapLayer* layer, int widgetIndex ) override;
virtual bool supportsLayer( QgsMapLayer *layer ) override;
};

@@ -145,7 +145,7 @@ void QgsLayerTreeView::modelRowsInserted( const QModelIndex& index, int start, i
if ( QgsLayerTreeEmbeddedWidgetProvider* provider = QgsLayerTreeEmbeddedWidgetRegistry::instance()->provider( providerId ) )
{
QModelIndex index = layerTreeModel()->legendNode2index( legendNodes[i] );
setIndexWidget( index, provider->createWidget( layer, QMap<QString, QString>() ) );
setIndexWidget( index, provider->createWidget( layer, i ) );
}
}
}
@@ -77,8 +77,9 @@ ADD_LIBRARY (georefplugin MODULE ${GEOREF_SRCS} ${GEOREF_MOC_SRCS} ${GEOREF_RCC_
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../../ui
../../core ../../core/geometry ../../core/raster ../../core/composer
../../gui ../../gui/editorwidgets
../../gui ../../gui/editorwidgets ../../gui/layertree
..
)
INCLUDE_DIRECTORIES(SYSTEM

0 comments on commit 301fd98

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