Skip to content

Commit

Permalink
fix for names of classification attributes in legend
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@4309 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 10, 2005
1 parent 172e114 commit 6f09aeb
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 32 deletions.
52 changes: 29 additions & 23 deletions src/legend/qgslegend.cpp
Expand Up @@ -52,9 +52,6 @@ QgsLegend::QgsLegend(QgisApp* app, QWidget * parent, const char *name)
connect( this, SIGNAL(selectionChanged(QTreeWidgetItem *)),
this, SLOT(updateLegendItem(QTreeWidgetItem *)) );

/*connect( this, SIGNAL(rightButtonPressed(QTreeWidgetItem *, const QPoint &, int)),
this, SLOT(handleRightClickEvent(QTreeWidgetItem*, const QPoint&)));*/

connect( this, SIGNAL(doubleClicked(QTreeWidgetItem *, const QPoint &, int)),
this, SLOT(handleDoubleClickEvent(QTreeWidgetItem*)));

Expand Down Expand Up @@ -124,6 +121,19 @@ void QgsLegend::mousePressEvent(QMouseEvent * e)
#ifdef QGISDEBUG
qWarning("this message comes from within QgsLegend::contentsMousePressEvent");
#endif

#if 0
//check, if a checkbox has been pressed
QWidget* w = childAt(e->pos());
QCheckBox* cb = dynamic_cast<QCheckBox*>(w);
if(cb)
{
#ifdef QGISDEBUG
qWarning("A checkbox has been pressed");
#endif
}
#endif

if (e->button() == Qt::LeftButton)
{
mLastPressPos = e->pos();
Expand Down Expand Up @@ -461,7 +471,7 @@ int QgsLegend::getItemPos(QTreeWidgetItem* item)

void QgsLegend::addLayer( QgsMapLayer * layer )
{
QgsLegendLayer * llayer = new QgsLegendLayer(this,QString(layer->name()));
QgsLegendLayer * llayer = new QgsLegendLayer(QString(layer->name()));
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup(llayer,QString("Files"));
QgsLegendLayerFile * llfile = new QgsLegendLayerFile(llfgroup, QgsLegendLayerFile::nameFromLayer(layer), layer);
QgsLegendSymbologyGroup * lsgroup = new QgsLegendSymbologyGroup(llayer,QString("Symbology"));
Expand All @@ -470,7 +480,9 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
layer->setLegendLayerFile(llfile);
layer->initContextMenu(mApp);

setExpanded(indexFromItem(llayer), true);
insertTopLevelItem(0, llayer);

setExpanded(indexFromItem(llayer), false);
setExpanded(indexFromItem(lpgroup), true);
setExpanded(indexFromItem(lsgroup), true);
setExpanded(indexFromItem(llfgroup), true);
Expand Down Expand Up @@ -627,28 +639,22 @@ void QgsLegend::legendLayerShowProperties()

void QgsLegend::expandAll()
{
#if 0
Q3ListViewItemIterator it(this);
while(it.current())
{
QTreeWidgetItem *item = it.current();
item->setOpen(true);
++it;
}
#endif
QTreeWidgetItem* theItem = firstItem();
while(theItem)
{
setExpanded(indexFromItem(theItem), true);
theItem = nextItem(theItem);
}
}

void QgsLegend::collapseAll()
{
#if 0
Q3ListViewItemIterator it(this);
while(it.current())
{
QTreeWidgetItem *item = it.current();
item->setOpen(false);
++it;
}
#endif
QTreeWidgetItem* theItem = firstItem();
while(theItem)
{
setExpanded(indexFromItem(theItem), false);
theItem = nextItem(theItem);
}
}

bool QgsLegend::writeXML( QDomNode & layer_node, QDomDocument & document )
Expand Down
6 changes: 6 additions & 0 deletions src/legend/qgslegenditem.cpp
Expand Up @@ -33,6 +33,7 @@ QgsLegendItem::QgsLegendItem(QTreeWidgetItem * theItem ,QString theName)
QString pkgDataPath(PKGDATAPATH);
#endif
QIcon myIcon(pkgDataPath+QString("/images/icons/group.png"));
setText(0, theName);
setIcon(0,myIcon);
}

Expand All @@ -45,9 +46,14 @@ QgsLegendItem::QgsLegendItem(QTreeWidget* theListView,QString theString)
QString pkgDataPath(PKGDATAPATH);
#endif
QIcon myIcon(pkgDataPath+QString("/images/icons/group.png"));
setText(0, theString);
setIcon(0,myIcon);
}

QgsLegendItem::QgsLegendItem(): QTreeWidgetItem()
{
}

QgsLegendItem::~QgsLegendItem()
{
}
Expand Down
1 change: 1 addition & 0 deletions src/legend/qgslegenditem.h
Expand Up @@ -38,6 +38,7 @@ class QgsLegendItem : public QTreeWidgetItem
public:
QgsLegendItem(QTreeWidgetItem*, QString);
QgsLegendItem (QTreeWidget*,QString);
QgsLegendItem();
~QgsLegendItem();

enum LEGEND_ITEM_TYPE
Expand Down
13 changes: 13 additions & 0 deletions src/legend/qgslegendlayer.cpp
Expand Up @@ -51,6 +51,19 @@ QgsLegendLayer::QgsLegendLayer(QTreeWidget* parent, QString name): QObject(), Qg
setIcon(0, myIcon);
}

QgsLegendLayer::QgsLegendLayer(QString name): QObject(), QgsLegendItem()
{
mType=LEGEND_LAYER;
#if defined(Q_OS_MACX) || defined(WIN32)
QString pkgDataPath(QCoreApplication::applicationDirPath()+QString("/share/qgis"));
#else
QString pkgDataPath(PKGDATAPATH);
#endif
QIcon myIcon(pkgDataPath+QString("/images/icons/layer.png"));
setText(0, name);
setIcon(0, myIcon);
}

QgsLegendLayer::~QgsLegendLayer()
{
mType=LEGEND_LAYER;
Expand Down
1 change: 1 addition & 0 deletions src/legend/qgslegendlayer.h
Expand Up @@ -38,6 +38,7 @@ class QgsLegendLayer : public QgsLegendItem, public QObject //for signal/ slot
public:
QgsLegendLayer(QTreeWidgetItem * ,QString);
QgsLegendLayer(QTreeWidget* ,QString);
QgsLegendLayer(QString name);
~QgsLegendLayer();
bool isLeafNode();
QgsLegendItem::DRAG_ACTION accept(LEGEND_ITEM_TYPE type);
Expand Down
5 changes: 5 additions & 0 deletions src/legend/qgslegendsymbologyitem.cpp
Expand Up @@ -25,6 +25,11 @@ QgsLegendSymbologyItem::QgsLegendSymbologyItem(QTreeWidgetItem * theItem,QString
mType = LEGEND_SYMBOL_ITEM;
}

QgsLegendSymbologyItem::QgsLegendSymbologyItem(): QgsLegendItem()
{
mType = LEGEND_SYMBOL_ITEM;
}

QgsLegendSymbologyItem::~QgsLegendSymbologyItem()
{
}
Expand Down
1 change: 1 addition & 0 deletions src/legend/qgslegendsymbologyitem.h
Expand Up @@ -29,6 +29,7 @@ class QgsLegendSymbologyItem : public QgsLegendItem
{
public:
QgsLegendSymbologyItem(QTreeWidgetItem* theItem, QString theString);
QgsLegendSymbologyItem();
~QgsLegendSymbologyItem();
bool isLeafNode() {return true;}
DRAG_ACTION accept(LEGEND_ITEM_TYPE type);
Expand Down
2 changes: 1 addition & 1 deletion src/qgscontinuouscolrenderer.h
Expand Up @@ -60,7 +60,7 @@ class QgsContinuousColRenderer: public QgsRenderer
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index of the classification attribute*/
virtual std::list<int> classificationAttributes() const;
std::list<int> classificationAttributes() const;
/**Returns the renderers name*/
QString name() const;
/**Return symbology items*/
Expand Down
2 changes: 1 addition & 1 deletion src/qgsgraduatedsymrenderer.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgsfeature.h"
#include "qgsgraduatedsymrenderer.h"
#include "qgsgrasydialog.h"
#include "qgslegenditem.h"
#include "qgslegendsymbologyitem.h"
#include "qgssymbologyutils.h"
#include "qgssvgcache.h"
#include <qdom.h>
Expand Down
5 changes: 3 additions & 2 deletions src/qgsgraduatedsymrenderer.h
Expand Up @@ -63,14 +63,15 @@ class QgsGraduatedSymRenderer: public QgsRenderer
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index to the classification field*/
virtual std::list<int> classificationAttributes() const;
std::list<int> classificationAttributes() const;
/**Returns the renderers name*/
QString name() const;
/**Returns the symbols of the items*/
const std::list<QgsSymbol*> symbols() const;
/**Returns a copy of the renderer (a deep copy on the heap)*/
QgsRenderer* clone() const;
protected:
/**Name of the classification field (it must be a numerical field)*/
/**Index of the classification field (it must be a numerical field)*/
int mClassificationField;
/**List holding the symbols for the individual classes*/
std::list<QgsSymbol*> mSymbols;
Expand Down
2 changes: 1 addition & 1 deletion src/qgsgrasydialog.cpp
Expand Up @@ -232,7 +232,7 @@ void QgsGraSyDialog::apply()
std::map<QString,int>::iterator iter=mFieldMap.find(classificationComboBox->currentText());
if(iter!=mFieldMap.end())
{
renderer->setClassificationField(iter->second);
renderer->setClassificationField(iter->second);
}
mVectorLayer->setRenderer(renderer);
mVectorLayer->refreshLegend();
Expand Down
1 change: 0 additions & 1 deletion src/qgsrenderer.cpp
Expand Up @@ -67,7 +67,6 @@ void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
}
item->setText(0, values);
}
//todo: add the name(s) of the classification field
}
}

1 change: 0 additions & 1 deletion src/qgsrenderer.h
Expand Up @@ -83,7 +83,6 @@ class QgsRenderer
protected:
/**Layer type*/
QGis::VectorType mVectorType;

};

inline void QgsRenderer::initialiseSelectionColor()
Expand Down
2 changes: 1 addition & 1 deletion src/qgssinglesymrenderer.h
Expand Up @@ -54,7 +54,7 @@ class QgsSingleSymRenderer: public QgsRenderer
/**Returns false, no attributes neede for single symbol*/
bool needsAttributes() const;
/**Returns an empty list, since no classification attributes are used*/
virtual std::list<int> classificationAttributes() const;
std::list<int> classificationAttributes() const;
/**Returns the renderers name*/
virtual QString name() const;
/**Returns a list containing mSymbol*/
Expand Down
4 changes: 3 additions & 1 deletion src/qgsvectorlayer.cpp
Expand Up @@ -2809,7 +2809,9 @@ void QgsVectorLayer::refreshLegend()
{
const QgsField theField = (dataProvider->fields())[*it];
QString classfieldname = theField.name();
QgsLegendVectorSymbologyItem* item = new QgsLegendVectorSymbologyItem(mLegendSymbologyGroupParent, classfieldname);
QgsLegendSymbologyItem* item = new QgsLegendSymbologyItem();
item->setText(0, classfieldname);
mLegendSymbologyGroupParent->insertChild(0, item);
}
}
}
Expand Down

0 comments on commit 6f09aeb

Please sign in to comment.