Skip to content

Commit

Permalink
Legend: apply overview and editing icons also to QgsLegendLayer if it…
Browse files Browse the repository at this point in the history
… has only one file. QgsOgrProvider: if a vector type is not known (e.g. for the ogr GML driver), examine the first layer feature to find out the wkb type

git-svn-id: http://svn.osgeo.org/qgis/trunk@5634 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jul 25, 2006
1 parent bd9046d commit 41015a3
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/gui/qgsmaplayer.h
Expand Up @@ -308,7 +308,6 @@ class QgsMapLayer : public QObject
*/
virtual QString errorString();


public slots:
/** \brief Mutator for transparency level. Should be between 0 and 255 */
virtual void setTransparency(unsigned int)=0;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsvectorlayer.cpp
Expand Up @@ -889,7 +889,7 @@ void QgsVectorLayer::draw(QPainter * p,
// only show selections of the current layer
bool sel;
if (
(mLegend->currentLayer() == this) &&
(mLegend && mLegend->currentLayer() == this) &&
(mSelectedFeatureIds.find(fet->featureId()) != mSelectedFeatureIds.end())
)
{
Expand Down
25 changes: 23 additions & 2 deletions src/legend/qgslegend.cpp
Expand Up @@ -652,7 +652,6 @@ void QgsLegend::legendLayerAddToOverview()
(*it)->inOverview(true);
}
}

mMapCanvas->updateOverview();
}

Expand All @@ -673,7 +672,6 @@ void QgsLegend::legendLayerRemoveFromOverview()
(*it)->inOverview(false); //else
}
}

mMapCanvas->updateOverview();
}

Expand Down Expand Up @@ -1064,6 +1062,7 @@ void QgsLegend::storeInitialPosition(QTreeWidgetItem* li)

void QgsLegend::resetToInitialPosition(QTreeWidgetItem* li)
{
QgsLegendItem* formerParent = dynamic_cast<QgsLegendItem*>(li->parent()); //todo: make sure legend layers are updated
if(mRestoreInformation == FIRST_ITEM)
{
#ifdef QGISDEBUG
Expand All @@ -1078,14 +1077,27 @@ void QgsLegend::resetToInitialPosition(QTreeWidgetItem* li)
qWarning("FIRST_CHILD");
#endif
removeItem(li);
if(formerParent)
{
formerParent->release((QgsLegendItem*)li);
}
mRestoreItem->insertChild(0, li);
((QgsLegendItem*)mRestoreItem)->receive((QgsLegendItem*)li);
}
else if(mRestoreInformation == YOUNGER_SIBLING)
{
#ifdef QGISDEBUG
qWarning("YOUNGER_SIBLING");
#endif
if(formerParent)
{
formerParent->release((QgsLegendItem*)li);
}
dynamic_cast<QgsLegendItem*>(li)->moveItem(dynamic_cast<QgsLegendItem*>(mRestoreItem));
if(mRestoreItem->parent())
{
((QgsLegendItem*)(mRestoreItem->parent()))->receive((QgsLegendItem*)li);
}
}
}

Expand Down Expand Up @@ -1253,14 +1265,23 @@ QDomNode QgsLegend::nextDomNode(const QDomNode& theNode)

void QgsLegend::insertItem(QTreeWidgetItem* move, QTreeWidgetItem* into)
{
#ifdef QGISDEBUG
qWarning("entering QgsLegend::insertItem");
#endif
QgsLegendItem* movedItem = dynamic_cast<QgsLegendItem*>(move);
QgsLegendItem* intoItem = dynamic_cast<QgsLegendItem*>(into);

if(movedItem && intoItem)
{
QgsLegendItem* parentItem = dynamic_cast<QgsLegendItem*>(movedItem->parent());
movedItem->storeAppearanceSettings();//store settings in the moved item and its children
removeItem(movedItem);
intoItem->insert(movedItem);
if(parentItem)
{
parentItem->release(movedItem); //give the former parent item the possibility to do cleanups
}
intoItem->receive(movedItem);
movedItem->restoreAppearanceSettings();//apply the settings again
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/legend/qgslegenditem.h
Expand Up @@ -98,6 +98,10 @@ class QgsLegendItem : public QTreeWidgetItem
void restoreAppearanceSettings();
/**Returns a pointer to the legend widget*/
QgsLegend* legend() const;
/**Do preparations after a new child was inserted (default empty)*/
virtual void receive(QgsLegendItem* newChild){}
/**Do cleanups after a child item leaves (default empty)*/
virtual void release(QgsLegendItem* formerChild){}
protected:
bool mLeafNodeFlag;
LEGEND_ITEM_TYPE mType;
Expand Down
60 changes: 57 additions & 3 deletions src/legend/qgslegendlayer.cpp
Expand Up @@ -17,13 +17,16 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "qgsapplication.h"
#include "qgslegendlayer.h"
#include "qgslegendlayerfile.h"
#include "qgslegendlayerfilegroup.h"
#include "qgsmaplayer.h"
#include <iostream>
#include <QCoreApplication>
#include <QIcon>
#include <QPainter>

QgsLegendLayer::QgsLegendLayer(QTreeWidgetItem* parent,QString name)
: QgsLegendItem(parent, name)
Expand Down Expand Up @@ -57,7 +60,7 @@ QgsLegendLayer::~QgsLegendLayer()

void QgsLegendLayer::setLayerTypeIcon()
{
QgsMapLayer* firstLayer = firstMapLayer();
/*QgsMapLayer* firstLayer = firstMapLayer();
if(firstLayer)
{
QFileInfo file(firstLayer->layerTypeIconPath());
Expand All @@ -66,7 +69,9 @@ void QgsLegendLayer::setLayerTypeIcon()
QIcon myIcon(file.absoluteFilePath());
setIcon(0, myIcon);
}
}
}*/
QIcon myIcon(getOriginalPixmap());
setIcon(0, myIcon);
}

bool QgsLegendLayer::isLeafNode()
Expand Down Expand Up @@ -110,7 +115,7 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayer::accept(const QgsLegendItem* li) const
return NO_ACTION;
}

QgsMapLayer* QgsLegendLayer::firstMapLayer()
QgsMapLayer* QgsLegendLayer::firstMapLayer() const
{
//first find the legend layer file group
QgsLegendLayerFileGroup* llfg = 0;
Expand Down Expand Up @@ -228,3 +233,52 @@ void QgsLegendLayer::updateCheckState()
treeWidget()->blockSignals(false);
}
}

void QgsLegendLayer::updateIcon()
{
QPixmap newIcon(getOriginalPixmap());

QgsMapLayer* theLayer = firstMapLayer();

if(mapLayers().size() == 1)
{

//overview
if(theLayer->showInOverviewStatus())
{
// Overlay the overview icon on the default icon
QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}

//editable
if(theLayer->isEditable())
{
// Overlay the editable icon on the default icon
QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");
QPainter p(&newIcon);
p.drawPixmap(0,0,myPixmap);
p.end();
}
}

QIcon theIcon(newIcon);
setIcon(0, theIcon);
}

QPixmap QgsLegendLayer::getOriginalPixmap() const
{
QgsMapLayer* firstLayer = firstMapLayer();
if(firstLayer)
{
QFileInfo file(firstLayer->layerTypeIconPath());
if(file.exists())
{
return QPixmap(file.absoluteFilePath());
}
}
QPixmap emptyPixmap;
return emptyPixmap;
}
7 changes: 6 additions & 1 deletion src/legend/qgslegendlayer.h
Expand Up @@ -50,7 +50,7 @@ class QgsLegendLayer : public QgsLegendItem
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;
/**Returns the map layer associated with the first QgsLegendLayerFile or 0 if
there is no QgsLegendLayerFile*/
QgsMapLayer* firstMapLayer();
QgsMapLayer* firstMapLayer() const;
/**Returns the map layers associated with the QgsLegendLayerFiles*/
std::list<QgsMapLayer*> mapLayers();
/**Returns the legend layer file items associated with this legend layer*/
Expand All @@ -61,6 +61,11 @@ class QgsLegendLayer : public QgsLegendItem
void updateLayerSymbologySettings(const QgsMapLayer* mapLayer);
/**Goes through all the legendlayerfiles and sets check state to checked/partially checked/unchecked*/
void updateCheckState();
/**Goes through all the legendlayerfiles and adds editing/overview pixmaps to the icon. If not all layer files
have the same editing/overview state, a tristate is applied*/
void updateIcon();
protected:
QPixmap getOriginalPixmap() const;
};

#endif
4 changes: 4 additions & 0 deletions src/legend/qgslegendlayerfile.cpp
Expand Up @@ -19,6 +19,7 @@
***************************************************************************/
#include "qgsapplication.h"
#include "qgslegend.h"
#include "qgslegendlayer.h"
#include "qgslegendlayerfile.h"
#include "qgsmaplayer.h"
#include <QCoreApplication>
Expand Down Expand Up @@ -121,6 +122,9 @@ void QgsLegendLayerFile::setIconAppearance(bool inOverview,

QIcon theIcon(newIcon);
setIcon(0, theIcon);

//also update the icon of the legend layer
((QgsLegendLayer*)(parent()->parent()))->updateIcon();
}

void QgsLegendLayerFile::toggleCheckBox(bool state)
Expand Down
47 changes: 47 additions & 0 deletions src/legend/qgslegendlayerfilegroup.cpp
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgslegendlayer.h"
#include "qgslegendlayerfilegroup.h"
#include "qgslegendlayerfile.h"
#include "qgslegendsymbologygroup.h"
Expand Down Expand Up @@ -72,12 +73,23 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayerFileGroup::accept(const QgsLegendItem*

bool QgsLegendLayerFileGroup::insert(QgsLegendItem* newItem)
{
#ifdef QGISDEBUG
qWarning("In QgsLegendLayerFileGroup::insert");
#endif
if ( newItem->type() == LEGEND_LAYER_FILE )
{
QgsLegendItem* oldItem = firstChild();
//QgsLegendLayer* parentLegendLayer = dynamic_cast<QgsLegendLayer*>(parent());

if(!oldItem)//this item is the first child
{
insertChild(0, newItem);
//update the icon and the check state of the new and the former legend layer
//if(parentLegendLayer)
//{
// parentLegendLayer->updateIcon();
// parentLegendLayer->updateCheckState();
//}
return true;
}
//there are already legend layer files
Expand All @@ -102,6 +114,12 @@ bool QgsLegendLayerFileGroup::insert(QgsLegendItem* newItem)
if(newLayer->isSymbologyCompatible(*thelayer))
{
insertChild(childCount(), newItem);
//update the icon and the check state of the new and the former legend layer
//if(parentLegendLayer)
//{
// parentLegendLayer->updateIcon();
// parentLegendLayer->updateCheckState();
//}
return true;
}
else
Expand All @@ -128,3 +146,32 @@ bool QgsLegendLayerFileGroup::containsLegendLayerFile(const QgsLegendLayerFile*
}
return result;
}

void QgsLegendLayerFileGroup::receive(QgsLegendItem* newChild)
{
if(newChild->type() == LEGEND_LAYER_FILE)
{
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(parent());
if(ll)
{
ll->updateIcon();
ll->updateCheckState();
}
}
}

void QgsLegendLayerFileGroup::release(QgsLegendItem* formerChild)
{
#ifdef QGISDEBUG
qWarning("In QgsLegendLayerFileGroup::release");
#endif
if(formerChild->type() == LEGEND_LAYER_FILE)
{
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(parent());
if(ll)
{
ll->updateIcon();
ll->updateCheckState();
}
}
}
6 changes: 6 additions & 0 deletions src/legend/qgslegendlayerfilegroup.h
Expand Up @@ -29,4 +29,10 @@ class QgsLegendLayerFileGroup: public QgsLegendItem
bool insert(QgsLegendItem* theItem);
/**Returns true if llf is a childelement*/
bool containsLegendLayerFile(const QgsLegendLayerFile* llf) const;
/**Makes the parent QgsLegendLayer update the checkState and the icon after a new
QgsLegendLayerFile was inserted*/
void receive(QgsLegendItem* newChild);
/**Cleanups when after a child QgsLegendLayerFile item has left. Tells the parent QgsLegendLayer to
refresh the checkState and the icon*/
void release(QgsLegendItem* formerChild);
};
18 changes: 18 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -186,6 +186,24 @@ void QgsOgrProvider::loadFields()
if(fdef)
{
geomType = fdef->GetGeomType();

//Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this.
//In such cases, we examine the first feature
if(geomType == wkbUnknown)
{
ogrLayer->ResetReading();
OGRFeature* firstFeature = ogrLayer->GetNextFeature();
if(firstFeature)
{
OGRGeometry* firstGeometry = firstFeature->GetGeometryRef();
if(firstGeometry)
{
geomType = firstGeometry->getGeometryType();
}
}
ogrLayer->ResetReading();
}

for(int i=0;i<fdef->GetFieldCount();++i)
{
OGRFieldDefn *fldDef = fdef->GetFieldDefn(i);
Expand Down

0 comments on commit 41015a3

Please sign in to comment.