Skip to content

Commit fc75d2d

Browse files
author
mhugent
committed
fix for legend crash when clicking 'show files' on empty legend
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5039 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 770464d commit fc75d2d

File tree

1 file changed

+6
-96
lines changed

1 file changed

+6
-96
lines changed

src/legend/qgslegend.cpp

+6-96
Original file line numberDiff line numberDiff line change
@@ -1410,102 +1410,6 @@ void QgsLegend::handleItemChange(QTreeWidgetItem* item, int row)
14101410
mStateOfCheckBoxes[item] = item->checkState(0);
14111411
}
14121412
}
1413-
#if 0
1414-
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup*>(item);
1415-
if(lg)
1416-
{
1417-
#ifdef QGISDEBUG
1418-
qWarning("detected legend group in QgsLegend::handleItemChange");
1419-
#endif
1420-
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
1421-
if(it != mStateOfCheckBoxes.end())
1422-
{
1423-
if(it->second != item->checkState(0)) //the checkState has changed
1424-
{
1425-
bool checked = (item->checkState(0) == Qt::Checked);
1426-
1427-
}
1428-
}
1429-
return;
1430-
}
1431-
1432-
QgsLegendLayerFile* llf = dynamic_cast<QgsLegendLayerFile*>(item);
1433-
if(llf)
1434-
{
1435-
#ifdef QGISDEBUG
1436-
qWarning("item is a QgsLegendLayerFile*");
1437-
#endif
1438-
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
1439-
if(it != mStateOfCheckBoxes.end())
1440-
{
1441-
if(it->second != item->checkState(0)) //the checkState has changed
1442-
{
1443-
QgsMapLayer* theLayer = llf->layer();
1444-
if(theLayer)
1445-
{
1446-
bool checked = (item->checkState(0) == Qt::Checked);
1447-
theLayer->setVisible(checked);
1448-
//check, how the checkbox of the legendlayer needs to be updated
1449-
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(item->parent()->parent());
1450-
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
1451-
std::list<QgsLegendLayerFile*>::iterator iter = llfiles.begin();
1452-
Qt::CheckState theState = (*iter)->checkState(0);
1453-
for(; iter != llfiles.end(); ++iter)
1454-
{
1455-
if(theState != (*iter)->checkState(0))
1456-
{
1457-
theState = Qt::PartiallyChecked;
1458-
break;
1459-
}
1460-
}
1461-
//and update the checkbox of the legendlayer if necessary
1462-
if(theState != ll->checkState(0));
1463-
{
1464-
blockSignals(true);
1465-
ll->setCheckState(0, theState);
1466-
mStateOfCheckBoxes[ll] = theState;
1467-
blockSignals(false);
1468-
}
1469-
}
1470-
mStateOfCheckBoxes[item] = item->checkState(0);
1471-
}
1472-
}
1473-
return;
1474-
}
1475-
1476-
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(item);
1477-
if(ll)
1478-
{
1479-
#ifdef QGISDEBUG
1480-
qWarning("item is a QgsLegendLayer");
1481-
#endif
1482-
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
1483-
if(it != mStateOfCheckBoxes.end())
1484-
{
1485-
if(it->second != item->checkState(0)) //the checkState has changed
1486-
{
1487-
bool checked = (item->checkState(0) == Qt::Checked);
1488-
std::list<QgsLegendLayerFile*> llflist = ll->legendLayerFiles();
1489-
mMapCanvas->setRenderFlag(false);
1490-
//go through all the legendlayerfiles and set their checkState
1491-
for(std::list<QgsLegendLayerFile*>::iterator it = llflist.begin(); it != llflist.end(); ++it)
1492-
{
1493-
if(checked)
1494-
{
1495-
(*it)->setCheckState(0, Qt::Checked);
1496-
mStateOfCheckBoxes[(*it)] = Qt::Checked;
1497-
}
1498-
else
1499-
{
1500-
(*it)->setCheckState(0, Qt::Unchecked);
1501-
mStateOfCheckBoxes[(*it)] = Qt::Unchecked;
1502-
}
1503-
}
1504-
mMapCanvas->setRenderFlag(true);
1505-
}
1506-
}
1507-
}
1508-
#endif //0
15091413
}
15101414

15111415
void QgsLegend::openEditor()
@@ -1536,6 +1440,12 @@ void QgsLegend::showLegendLayerFileGroups()
15361440

15371441
QgsLegendLayerFileGroup* theFileGroup = 0;
15381442
QTreeWidgetItem* theItem = firstItem();
1443+
1444+
if(!theItem)
1445+
{
1446+
return;
1447+
}
1448+
15391449
do
15401450
{
15411451
theFileGroup = dynamic_cast<QgsLegendLayerFileGroup*>(theItem);

0 commit comments

Comments
 (0)