[QGIS Commit] r13383 - in trunk/qgis: python/gui src/app/legend
src/gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Apr 25 13:26:13 EDT 2010
Author: wonder
Date: 2010-04-25 13:26:12 -0400 (Sun, 25 Apr 2010)
New Revision: 13383
Modified:
trunk/qgis/python/gui/qgslegendinterface.sip
trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
trunk/qgis/src/app/legend/qgsapplegendinterface.h
trunk/qgis/src/app/legend/qgslegend.cpp
trunk/qgis/src/app/legend/qgslegend.h
trunk/qgis/src/gui/qgslegendinterface.h
Log:
Applied patch from #2672 by Andres Manz: more legend interface functionality.
Thanks for contributing.
Modified: trunk/qgis/python/gui/qgslegendinterface.sip
===================================================================
--- trunk/qgis/python/gui/qgslegendinterface.sip 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/python/gui/qgslegendinterface.sip 2010-04-25 17:26:12 UTC (rev 13383)
@@ -21,8 +21,24 @@
//! Return all layers in the project in legend order
//! @note added in 1.5
- virtual QList< QgsMapLayer * > layers() const = 0;
+ virtual QList< QgsMapLayer * > layers() const =0;
+ //! Check if a group exists
+ //! @note added in 1.5
+ virtual bool groupExists( int groupIndex ) =0;
+
+ //! Check if a group is expanded
+ //! @note added in 1.5
+ virtual bool isGroupExpanded( int groupIndex ) =0;
+
+ //! Check if a group is visible
+ //! @note added in 1.5
+ virtual bool isGroupVisible( int groupIndex ) =0;
+
+ //! Check if a layer is visible
+ //! @note added in 1.5
+ virtual bool isLayerVisible( QgsMapLayer * ml ) =0;
+
signals:
//! emitted when a group index has changed
@@ -39,8 +55,20 @@
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * layer, int groupIndex ) =0;
+ //! Collapse or expand a group
+ //! @note added in 1.5
+ virtual void setGroupExpanded( int groupIndex, bool expand ) =0;
+
+ //! Set the visibility of a group
+ //! @note added in 1.5
+ virtual void setGroupVisible( int groupIndex, bool visible ) =0;
+
+ //! Set the visibility of a layer
+ //! @note added in 1.5
+ virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) =0;
+
//! refresh layer symbology
- //! \note added in 1.5
+ //! @note added in 1.5
virtual void refreshLayerSymbology( QgsMapLayer *layer ) =0;
};
Modified: trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgsapplegendinterface.cpp 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/src/app/legend/qgsapplegendinterface.cpp 2010-04-25 17:26:12 UTC (rev 13383)
@@ -54,11 +54,59 @@
}
}
+void QgsAppLegendInterface::setGroupExpanded( int groupIndex, bool expand )
+{
+ mLegend->setExpanded( mLegend->model()->index( groupIndex, 0 ), expand );
+}
+
+void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
+{
+ if ( !groupExists( groupIndex ) )
+ {
+ return;
+ }
+
+ Qt::CheckState state = visible ? Qt::Checked : Qt::Unchecked;
+ mLegend->topLevelItem( groupIndex )->setCheckState( 0, state );
+}
+
+void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
+{
+ mLegend->setLayerVisible( ml, visible );
+}
+
QStringList QgsAppLegendInterface::groups()
{
return mLegend->groups();
}
+bool QgsAppLegendInterface::groupExists( int groupIndex )
+{
+ QModelIndex mi = mLegend->model()->index( groupIndex, 0 );
+ return ( mi.isValid() &&
+ mLegend->isLegendGroup( mi ) );
+}
+
+bool QgsAppLegendInterface::isGroupExpanded( int groupIndex )
+{
+ return mLegend->isExpanded( mLegend->model()->index( groupIndex, 0 ) );
+}
+
+bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
+{
+ if ( !groupExists( groupIndex ) )
+ {
+ return false;
+ }
+
+ return ( Qt::Checked == mLegend->topLevelItem( groupIndex )->checkState( 0 ) );
+}
+
+bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
+{
+ return ( Qt::Checked == mLegend->layerCheckState( ml ) );
+}
+
QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
QList< QgsMapLayer * > items;
Modified: trunk/qgis/src/app/legend/qgsapplegendinterface.h
===================================================================
--- trunk/qgis/src/app/legend/qgsapplegendinterface.h 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/src/app/legend/qgsapplegendinterface.h 2010-04-25 17:26:12 UTC (rev 13383)
@@ -38,7 +38,7 @@
/** Constructor */
explicit QgsAppLegendInterface( QgsLegend * legend );
- /** Virtual destructor */
+ /** Destructor */
~QgsAppLegendInterface();
//! Return a string list of groups
@@ -47,6 +47,18 @@
//! Return all layers in the project in legend order
QList< QgsMapLayer * > layers() const;
+ //! Check if a group exists
+ bool groupExists( int groupIndex );
+
+ //! Check if a group is expanded
+ bool isGroupExpanded( int groupIndex );
+
+ //! Check if a group is visible
+ bool isGroupVisible( int groupIndex );
+
+ //! Check if a layer is visible
+ bool isLayerVisible( QgsMapLayer * ml );
+
public slots:
//! Add a new group
@@ -61,6 +73,15 @@
//! Update an index
void updateIndex( QModelIndex oldIndex, QModelIndex newIndex );
+ //! Collapse or expand a group
+ virtual void setGroupExpanded( int groupIndex, bool expand );
+
+ //! Set the visibility of a group
+ virtual void setGroupVisible( int groupIndex, bool visible );
+
+ //! Set the visibility of a layer
+ virtual void setLayerVisible( QgsMapLayer * ml, bool visible );
+
//! refresh layer symbology
void refreshLayerSymbology( QgsMapLayer *ml );
Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/src/app/legend/qgslegend.cpp 2010-04-25 17:26:12 UTC (rev 13383)
@@ -480,6 +480,13 @@
mPixmaps.mProjectionErrorPixmap = QgisApp::getThemePixmap( "/mIconProjectionProblem.png" );
}
+Qt::CheckState QgsLegend::layerCheckState( QgsMapLayer * layer )
+{
+ QgsLegendLayer * ll = findLegendLayer( layer );
+
+ return ll ? ll->checkState( 0 ) : Qt::Unchecked;
+}
+
int QgsLegend::getItemPos( QTreeWidgetItem* item )
{
int counter = 1;
@@ -548,6 +555,16 @@
doItemsLayout();
}
+void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )
+{
+ QgsLegendLayer * ll = findLegendLayer( layer );
+ if ( ll )
+ {
+ Qt::CheckState cs = visible ? Qt::Checked : Qt::Unchecked;
+ ll->setCheckState( 0, cs );
+ }
+}
+
void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
{
if ( mMapCanvas )
Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/src/app/legend/qgslegend.h 2010-04-25 17:26:12 UTC (rev 13383)
@@ -179,7 +179,10 @@
/**Returns structure with legend pixmaps*/
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
+ /**Returns a layers check state*/
+ Qt::CheckState layerCheckState( QgsMapLayer * layer );
+
void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) { item->setData( 0, Qt::UserRole, state ); }
public slots:
@@ -187,6 +190,8 @@
/*!Adds a new layer group with the maplayer to the canvas*/
void addLayer( QgsMapLayer * layer );
+ void setLayerVisible( QgsMapLayer * layer, bool visible );
+
void setMapCanvas( QgsMapCanvas * canvas );
/**Updates symbology items for a layer*/
Modified: trunk/qgis/src/gui/qgslegendinterface.h
===================================================================
--- trunk/qgis/src/gui/qgslegendinterface.h 2010-04-25 15:06:51 UTC (rev 13382)
+++ trunk/qgis/src/gui/qgslegendinterface.h 2010-04-25 17:26:12 UTC (rev 13383)
@@ -48,6 +48,22 @@
//! @note added in 1.5
virtual QList< QgsMapLayer * > layers() const = 0;
+ //! Check if a group exists
+ //! @note added in 1.5
+ virtual bool groupExists( int groupIndex ) = 0;
+
+ //! Check if a group is expanded
+ //! @note added in 1.5
+ virtual bool isGroupExpanded( int groupIndex ) = 0;
+
+ //! Check if a group is visible
+ //! @note added in 1.5
+ virtual bool isGroupVisible( int groupIndex ) = 0;
+
+ //! Check if a layer is visible
+ //! @note added in 1.5
+ virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
+
signals:
//! emitted when a group index has changed
@@ -64,8 +80,20 @@
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
+ //! Collapse or expand a group
+ //! @note added in 1.5
+ virtual void setGroupExpanded( int groupIndex, bool expand ) = 0;
+
+ //! Set the visibility of a group
+ //! @note added in 1.5
+ virtual void setGroupVisible( int groupIndex, bool visible ) = 0;
+
+ //! Set the visibility of a layer
+ //! @note added in 1.5
+ virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) = 0;
+
//! Refresh layer symbology
- // @noted added in 1.5
+ //! @note added in 1.5
virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
};
More information about the QGIS-commit
mailing list