Skip to content

Commit 64eeec8

Browse files
author
jef
committed
little legend cleanup: remove member mStateOfCheckBoxes
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12076 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 80ecf23 commit 64eeec8

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

src/app/legend/qgslegend.cpp

+15-25
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,12 @@ void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetI
119119
void QgsLegend::addGroup()
120120
{
121121
QgsLegendGroup* group = new QgsLegendGroup( this, tr( "group" ) );
122-
mStateOfCheckBoxes.insert( std::make_pair( group, Qt::Checked ) ); //insert the check state into the map to query for changes later
122+
group->setData( 0, Qt::UserRole, Qt::Checked );
123123
setExpanded( indexFromItem( group ), true );
124124
}
125125

126126
void QgsLegend::removeAll()
127127
{
128-
mStateOfCheckBoxes.clear();
129128
clear();
130129
mPixmapWidthValues.clear();
131130
mPixmapHeightValues.clear();
@@ -182,8 +181,6 @@ void QgsLegend::removeLayer( QString layer_key )
182181

183182
if ( ll && ll->layer() && ll->layer()->getLayerID() == layer_key )
184183
{
185-
//remove the map entry for the checkbox
186-
mStateOfCheckBoxes.erase( ll );
187184
removeItem( ll );
188185
delete ll;
189186

@@ -501,12 +498,12 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
501498
if ( llayer->isVisible() )
502499
{
503500
llayer->setCheckState( 0, Qt::Checked );
504-
mStateOfCheckBoxes.insert( std::make_pair( llayer, Qt::Checked ) );
501+
llayer->setData( 0, Qt::UserRole, Qt::Checked );
505502
}
506503
else
507504
{
508505
llayer->setCheckState( 0, Qt::Unchecked );
509-
mStateOfCheckBoxes.insert( std::make_pair( llayer, Qt::Unchecked ) );
506+
llayer->setData( 0, Qt::UserRole, Qt::Unchecked );
510507
}
511508
blockSignals( false );
512509

@@ -909,7 +906,6 @@ bool QgsLegend::readXML( QDomNode& legendnode )
909906
if ( !child.isNull() )
910907
{
911908
clear(); //remove all items first
912-
mStateOfCheckBoxes.clear();
913909

914910
do
915911
{
@@ -927,24 +923,24 @@ bool QgsLegend::readXML( QDomNode& legendnode )
927923
if ( checked == "Qt::Checked" )
928924
{
929925
theGroup->setCheckState( 0, Qt::Checked );
930-
mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::Checked ) );
926+
theGroup->setData( 0, Qt::UserRole, Qt::Checked );
931927
}
932928
else if ( checked == "Qt::Unchecked" )
933929
{
934930
theGroup->setCheckState( 0, Qt::Unchecked );
935-
mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::Unchecked ) );
931+
theGroup->setData( 0, Qt::UserRole, Qt::Checked );
936932
}
937933
else if ( checked == "Qt::PartiallyChecked" )
938934
{
939935
theGroup->setCheckState( 0, Qt::PartiallyChecked );
940-
mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::PartiallyChecked ) );
936+
theGroup->setData( 0, Qt::UserRole, Qt::PartiallyChecked );
941937
}
942938
blockSignals( false );
943939
lastGroup = theGroup;
944940
}
945941
else if ( childelem.tagName() == "legendlayer" )
946942
{
947-
bool isOpen; // to recieve info whether the item is open or closed
943+
bool isOpen; // to receive info whether the item is open or closed
948944
lastLayer = readLayerFromXML(childelem, isOpen);
949945

950946
if (lastLayer)
@@ -1039,13 +1035,13 @@ QgsLegendLayer* QgsLegend::readLayerFromXML(QDomElement& childelem, bool& isOpen
10391035
{
10401036
ll->setVisible(true);
10411037
ll->setCheckState( 0, Qt::Checked );
1042-
mStateOfCheckBoxes.insert( std::make_pair( ll, Qt::Checked ) );
1038+
ll->setData( 0, Qt::UserRole, Qt::Checked );
10431039
}
10441040
else if ( checked == "Qt::Unchecked" )
10451041
{
10461042
ll->setVisible(false);
10471043
ll->setCheckState( 0, Qt::Unchecked );
1048-
mStateOfCheckBoxes.insert( std::make_pair( ll, Qt::Unchecked ) );
1044+
ll->setData( 0, Qt::UserRole, Qt::Unchecked );
10491045
}
10501046
blockSignals( false );
10511047

@@ -1336,8 +1332,6 @@ void QgsLegend::removeItem( QTreeWidgetItem* item )
13361332

13371333
void QgsLegend::updateMapCanvasLayerSet()
13381334
{
1339-
//std::deque<QString> layers = layerIDs();
1340-
13411335
QList<QgsMapCanvasLayer> layers;
13421336

13431337
// create list of the layers
@@ -1484,12 +1478,8 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
14841478
theLegendLayer->layer()->setLayerName( theLegendLayer->text( 0 ) );
14851479
}
14861480

1487-
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find( item );
1488-
if ( it == mStateOfCheckBoxes.end() )
1489-
return;
1490-
14911481
// has the checkState changed?
1492-
if ( it->second == item->checkState( 0 ) )
1482+
if ( item->data(0, Qt::UserRole).toInt() == item->checkState( 0 ) )
14931483
return;
14941484

14951485
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item ); //item is a legend group
@@ -1518,7 +1508,7 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
15181508
blockSignals( true );
15191509
( *iter )->setCheckState( 0, item->checkState( 0 ) );
15201510
blockSignals( false );
1521-
mStateOfCheckBoxes[( *iter )] = item->checkState( 0 );
1511+
item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
15221512
if (( *iter )->layer() )
15231513
{
15241514
( *iter )->setVisible( item->checkState( 0 ) == Qt::Checked );
@@ -1529,7 +1519,7 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
15291519
// off, as turning it on causes a refresh.
15301520
if ( renderFlagState )
15311521
mMapCanvas->setRenderFlag( true );
1532-
mStateOfCheckBoxes[item] = item->checkState( 0 );
1522+
item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
15331523
}
15341524

15351525
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item ); //item is a legend layer
@@ -1538,7 +1528,7 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
15381528
blockSignals( true );
15391529
ll->setCheckState( 0, item->checkState( 0 ) );
15401530
blockSignals( false );
1541-
mStateOfCheckBoxes[ll] = item->checkState( 0 );
1531+
ll->setData( 0, Qt::UserRole, ll->checkState( 0 ) );
15421532
if (ll->layer() )
15431533
{
15441534
ll->setVisible( item->checkState( 0 ) == Qt::Checked );
@@ -1547,7 +1537,7 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
15471537
if ( ll->parent() )
15481538
{
15491539
static_cast<QgsLegendGroup*>( ll->parent() )->updateCheckState();
1550-
mStateOfCheckBoxes[ll->parent()] = ll->parent()->checkState( 0 );
1540+
ll->parent()->setData( 0, Qt::UserRole, ll->parent()->checkState( 0 ) );
15511541
}
15521542
// If it was on, turn it back on, otherwise leave it
15531543
// off, as turning it on causes a refresh.
@@ -1557,7 +1547,7 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
15571547
}
15581548
mMapCanvas->freeze( false );
15591549
//update check state of the legend group
1560-
mStateOfCheckBoxes[item] = item->checkState( 0 );
1550+
item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
15611551
}
15621552

15631553
// update layer set

src/app/legend/qgslegend.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class QgsLegend : public QTreeWidget
169169
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
170170

171171

172-
void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) {mStateOfCheckBoxes[item] = state;}
172+
void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) { item->setData( 0, Qt::UserRole, state ); }
173173

174174
public slots:
175175

@@ -404,10 +404,6 @@ class QgsLegend : public QTreeWidget
404404
/**Pointer to the main canvas. Used for requiring repaints in case of legend changes*/
405405
QgsMapCanvas* mMapCanvas;
406406

407-
/**Map that keeps track of which checkboxes are in which check state. This is necessary because QTreeView does not emit
408-
a signal for check state changes*/
409-
std::map<QTreeWidgetItem*, Qt::CheckState> mStateOfCheckBoxes;
410-
411407
/**Stores the width values of the LegendSymbologyItem pixmaps. The purpose of this is that the legend may automatically change
412408
the global IconWidth when items are added or removed*/
413409
std::multiset<int> mPixmapWidthValues;

src/app/legend/qgslegendlayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
385385
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
386386

387387
// attribute table
388-
QAction* tableAction = theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
388+
theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
389389

390390
// allow editing
391391
int cap = vlayer->dataProvider()->capabilities();
@@ -399,7 +399,7 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
399399
}
400400

401401
// save as shapefile
402-
QAction* saveShpAction = theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
402+
theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
403403

404404
// save selection as shapefile
405405
QAction* saveSelectionAction = theMenu.addAction( tr( "Save selection as shapefile..." ), this, SLOT( saveSelectionAsShapefile() ) );

0 commit comments

Comments
 (0)