[QGIS Commit] r14523 - trunk/qgis/src/app/legend
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Nov 6 19:24:53 EDT 2010
Author: jef
Date: 2010-11-06 16:24:53 -0700 (Sat, 06 Nov 2010)
New Revision: 14523
Modified:
trunk/qgis/src/app/legend/qgslegend.cpp
trunk/qgis/src/app/legend/qgslegend.h
trunk/qgis/src/app/legend/qgslegendgroup.cpp
Log:
fix legend
Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp 2010-11-06 22:52:03 UTC (rev 14522)
+++ trunk/qgis/src/app/legend/qgslegend.cpp 2010-11-06 23:24:53 UTC (rev 14523)
@@ -48,10 +48,10 @@
const int AUTOSCROLL_MARGIN = 16;
QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
- : QTreeWidget( parent )
- , mMousePressedFlag( false )
- , mMapCanvas( canvas )
- , mMinimumIconSize( 20, 20 )
+ : QTreeWidget( parent )
+ , mMousePressedFlag( false )
+ , mMapCanvas( canvas )
+ , mMinimumIconSize( 20, 20 )
{
setObjectName( name );
@@ -161,7 +161,6 @@
else
group = new QgsLegendGroup( this, name );
- group->setData( 0, Qt::UserRole, Qt::Checked );
QModelIndex groupIndex = indexFromItem( group );
setExpanded( groupIndex, expand );
setCurrentItem( group );
@@ -235,7 +234,6 @@
delete ll;
break;
}
-
}
}
@@ -280,14 +278,14 @@
QgsDebugMsg( "layers prior to move: " + mLayersPriorToMove.join( ", " ) );
// record which items were selected and hide them
- foreach( QTreeWidgetItem *item, selectedItems() )
+ foreach( QTreeWidgetItem * item, selectedItems() )
{
item->setHidden( true );
mItemsBeingMoved << item;
}
// remove and unhide items, whose parent is already to be moved
- foreach( QTreeWidgetItem *item, mItemsBeingMoved )
+ foreach( QTreeWidgetItem * item, mItemsBeingMoved )
{
QTreeWidgetItem *parent = item->parent();
@@ -423,7 +421,7 @@
hideLine();
// unhide
- foreach( QTreeWidgetItem *item, mItemsBeingMoved )
+ foreach( QTreeWidgetItem * item, mItemsBeingMoved )
{
item->setHidden( false );
}
@@ -441,7 +439,7 @@
showItem( "prev sibling", mDropTarget );
- foreach( QTreeWidgetItem *item, mItemsBeingMoved )
+ foreach( QTreeWidgetItem * item, mItemsBeingMoved )
{
moveItem( item, mDropTarget );
mDropTarget = item;
@@ -468,7 +466,7 @@
{
showItem( "drop after", mDropTarget );
- foreach( QTreeWidgetItem *item, mItemsBeingMoved )
+ foreach( QTreeWidgetItem * item, mItemsBeingMoved )
{
moveItem( item, mDropTarget );
mDropTarget = item;
@@ -479,7 +477,7 @@
{
showItem( "insert into", mDropTarget );
- foreach( QTreeWidgetItem *item, mItemsBeingMoved )
+ foreach( QTreeWidgetItem * item, mItemsBeingMoved )
{
insertItem( item, mDropTarget );
}
@@ -592,12 +590,10 @@
if ( llayer->isVisible() )
{
llayer->setCheckState( 0, Qt::Checked );
- llayer->setData( 0, Qt::UserRole, Qt::Checked );
}
else
{
llayer->setCheckState( 0, Qt::Unchecked );
- llayer->setData( 0, Qt::UserRole, Qt::Unchecked );
}
blockSignals( false );
@@ -677,7 +673,7 @@
{
QList<QgsMapLayer *> layers;
- foreach( QTreeWidgetItem *item, selectedItems() )
+ foreach( QTreeWidgetItem * item, selectedItems() )
{
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
if ( ll )
@@ -803,7 +799,7 @@
bool QgsLegend::writeXML( QList<QTreeWidgetItem *> items, QDomNode &node, QDomDocument &document )
{
- foreach( QTreeWidgetItem *currentItem, items )
+ foreach( QTreeWidgetItem * currentItem, items )
{
QgsLegendItem *item = dynamic_cast<QgsLegendItem *>( currentItem );
if ( !item )
@@ -944,17 +940,14 @@
if ( checked == "Qt::Checked" )
{
theGroup->setCheckState( 0, Qt::Checked );
- theGroup->setData( 0, Qt::UserRole, Qt::Checked );
}
else if ( checked == "Qt::Unchecked" )
{
theGroup->setCheckState( 0, Qt::Unchecked );
- theGroup->setData( 0, Qt::UserRole, Qt::Checked );
}
else if ( checked == "Qt::PartiallyChecked" )
{
theGroup->setCheckState( 0, Qt::PartiallyChecked );
- theGroup->setData( 0, Qt::UserRole, Qt::PartiallyChecked );
}
blockSignals( false );
@@ -1070,13 +1063,11 @@
{
ll->setVisible( true );
ll->setCheckState( 0, Qt::Checked );
- ll->setData( 0, Qt::UserRole, Qt::Checked );
}
else if ( checked == "Qt::Unchecked" )
{
ll->setVisible( false );
ll->setCheckState( 0, Qt::Unchecked );
- ll->setData( 0, Qt::UserRole, Qt::Unchecked );
}
blockSignals( false );
@@ -1535,14 +1526,23 @@
if ( item->data( 0, Qt::UserRole ).toInt() == item->checkState( 0 ) )
return;
+ saveCheckStates( invisibleRootItem() );
+
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
- foreach( QTreeWidgetItem *i, selectedItems() )
+ if ( !item->isSelected() )
{
- propagateItemChange( i, item->checkState( 0 ) );
+ propagateItemChange( item, item->checkState( 0 ) );
}
+ else
+ {
+ foreach( QTreeWidgetItem * i, selectedItems() )
+ {
+ propagateItemChange( i, item->checkState( 0 ) );
+ }
+ }
// update layer set
updateMapCanvasLayerSet();
@@ -1553,6 +1553,16 @@
mMapCanvas->setRenderFlag( true );
}
+void QgsLegend::saveCheckStates( QTreeWidgetItem *item )
+{
+ for ( int i = 0; i < item->childCount(); i++ )
+ {
+ QTreeWidgetItem *child = item->child( i );
+ child->setData( 0, Qt::UserRole, child->checkState( 0 ) );
+ saveCheckStates( child );
+ }
+}
+
void QgsLegend::propagateItemChange( QTreeWidgetItem *item, Qt::CheckState state )
{
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item ); //item is a legend group
@@ -1588,8 +1598,6 @@
items << lg->child( i );
}
}
-
- item->setData( 0, Qt::UserRole, state );
}
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item ); //item is a legend layer
@@ -1597,8 +1605,7 @@
{
blockSignals( true );
ll->setCheckState( 0, state );
- blockSignals( false );
- ll->setData( 0, Qt::UserRole, ll->checkState( 0 ) );
+
if ( ll->layer() )
{
ll->setVisible( state == Qt::Checked );
@@ -1608,11 +1615,10 @@
while ( lg )
{
lg->updateCheckState();
- lg->setData( 0, Qt::UserRole, lg->checkState( 0 ) );
lg = dynamic_cast<QgsLegendGroup*>( lg->parent() );
}
- //update check state of the legend group
- item->setData( 0, Qt::UserRole, state );
+
+ blockSignals( false );
}
}
@@ -1820,7 +1826,7 @@
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
- foreach( QTreeWidgetItem *item, selectedItems() )
+ foreach( QTreeWidgetItem * item, selectedItems() )
{
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item );
if ( lg )
Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h 2010-11-06 22:52:03 UTC (rev 14522)
+++ trunk/qgis/src/app/legend/qgslegend.h 2010-11-06 23:24:53 UTC (rev 14523)
@@ -419,6 +419,9 @@
/**QgsLegend does not set the icon with/height to values lower than the minimum icon size*/
QSize mMinimumIconSize;
+ /** save item check states */
+ void saveCheckStates( QTreeWidgetItem *item );
+
/** structure which holds pixmap which are used in legend */
class QgsLegendPixmaps
{
Modified: trunk/qgis/src/app/legend/qgslegendgroup.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendgroup.cpp 2010-11-06 22:52:03 UTC (rev 14522)
+++ trunk/qgis/src/app/legend/qgslegendgroup.cpp 2010-11-06 23:24:53 UTC (rev 14523)
@@ -25,7 +25,7 @@
#include <QIcon>
QgsLegendGroup::QgsLegendGroup( QTreeWidgetItem * theItem, QString theName )
- : QgsLegendItem( theItem, theName )
+ : QgsLegendItem( theItem, theName )
{
mType = LEGEND_GROUP;
setFlags( Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
@@ -34,7 +34,7 @@
setIcon( 0, myIcon );
}
QgsLegendGroup::QgsLegendGroup( QTreeWidget* theListView, QString theString )
- : QgsLegendItem( theListView, theString )
+ : QgsLegendItem( theListView, theString )
{
mType = LEGEND_GROUP;
setFlags( Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
@@ -114,7 +114,7 @@
return;
Qt::CheckState theState = elements[0]->checkState( 0 );
- foreach( QgsLegendItem *li, elements )
+ foreach( QgsLegendItem * li, elements )
{
if ( theState != li->checkState( 0 ) )
{
@@ -125,8 +125,6 @@
if ( theState != checkState( 0 ) )
{
- treeWidget()->blockSignals( true );
setCheckState( 0, theState );
- treeWidget()->blockSignals( false );
}
}
More information about the QGIS-commit
mailing list