Skip to content
Permalink
Browse files

fix for legend crash when clicking 'show files' on empty legend

git-svn-id: http://svn.osgeo.org/qgis/trunk@5039 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Mar 16, 2006
1 parent af95217 commit b22661ea911de4acee71f64b2341461c2f7db685
Showing with 6 additions and 96 deletions.
  1. +6 −96 src/legend/qgslegend.cpp
@@ -1410,102 +1410,6 @@ void QgsLegend::handleItemChange(QTreeWidgetItem* item, int row)
mStateOfCheckBoxes[item] = item->checkState(0);
}
}
#if 0
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup*>(item);
if(lg)
{
#ifdef QGISDEBUG
qWarning("detected legend group in QgsLegend::handleItemChange");
#endif
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
if(it != mStateOfCheckBoxes.end())
{
if(it->second != item->checkState(0)) //the checkState has changed
{
bool checked = (item->checkState(0) == Qt::Checked);

}
}
return;
}

QgsLegendLayerFile* llf = dynamic_cast<QgsLegendLayerFile*>(item);
if(llf)
{
#ifdef QGISDEBUG
qWarning("item is a QgsLegendLayerFile*");
#endif
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
if(it != mStateOfCheckBoxes.end())
{
if(it->second != item->checkState(0)) //the checkState has changed
{
QgsMapLayer* theLayer = llf->layer();
if(theLayer)
{
bool checked = (item->checkState(0) == Qt::Checked);
theLayer->setVisible(checked);
//check, how the checkbox of the legendlayer needs to be updated
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(item->parent()->parent());
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
std::list<QgsLegendLayerFile*>::iterator iter = llfiles.begin();
Qt::CheckState theState = (*iter)->checkState(0);
for(; iter != llfiles.end(); ++iter)
{
if(theState != (*iter)->checkState(0))
{
theState = Qt::PartiallyChecked;
break;
}
}
//and update the checkbox of the legendlayer if necessary
if(theState != ll->checkState(0));
{
blockSignals(true);
ll->setCheckState(0, theState);
mStateOfCheckBoxes[ll] = theState;
blockSignals(false);
}
}
mStateOfCheckBoxes[item] = item->checkState(0);
}
}
return;
}

QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(item);
if(ll)
{
#ifdef QGISDEBUG
qWarning("item is a QgsLegendLayer");
#endif
std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find(item);
if(it != mStateOfCheckBoxes.end())
{
if(it->second != item->checkState(0)) //the checkState has changed
{
bool checked = (item->checkState(0) == Qt::Checked);
std::list<QgsLegendLayerFile*> llflist = ll->legendLayerFiles();
mMapCanvas->setRenderFlag(false);
//go through all the legendlayerfiles and set their checkState
for(std::list<QgsLegendLayerFile*>::iterator it = llflist.begin(); it != llflist.end(); ++it)
{
if(checked)
{
(*it)->setCheckState(0, Qt::Checked);
mStateOfCheckBoxes[(*it)] = Qt::Checked;
}
else
{
(*it)->setCheckState(0, Qt::Unchecked);
mStateOfCheckBoxes[(*it)] = Qt::Unchecked;
}
}
mMapCanvas->setRenderFlag(true);
}
}
}
#endif //0
}

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

QgsLegendLayerFileGroup* theFileGroup = 0;
QTreeWidgetItem* theItem = firstItem();

if(!theItem)
{
return;
}

do
{
theFileGroup = dynamic_cast<QgsLegendLayerFileGroup*>(theItem);

0 comments on commit b22661e

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