mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-26 00:02:08 -05:00
- legend item check boxes work again
- fixed feature select bug Note: QGuardedPtr should only be used for classes that use MOC. QgsRec doesn't use MOC, therefore it shouldn't have used QGuardedPtr. Worse yet, you can't use std::auto_ptr because its pass-responsibility-by-copy semantics make it a Bad Idea to use as a parameter, which is what would have happened with the QgsRec that was causing feature selection to blow up. Currently we have no available general reference-counting smart-pointer classes. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1336 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
fd6b2ba04e
commit
e175dfc1ce
@ -28,6 +28,7 @@ QgsLegendItem::QgsLegendItem(QgsMapLayer * lyr, QListView * parent)
|
||||
m_layer(lyr),
|
||||
layerName( lyr->name() )
|
||||
{
|
||||
activate();
|
||||
setOn(lyr->visible());
|
||||
setPixmap( 0, *lyr->legendPixmap() );
|
||||
}
|
||||
@ -56,10 +57,10 @@ void QgsLegendItem::setLayerName(const QString & _newVal)
|
||||
// displayName = _newVal;
|
||||
// }
|
||||
|
||||
// void QgsLegendItem::stateChange(bool vis)
|
||||
// {
|
||||
// m_layer->setVisible(vis);
|
||||
// }
|
||||
void QgsLegendItem::stateChange(bool vis)
|
||||
{
|
||||
m_layer->setVisible(vis);
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsLegendItem::layer()
|
||||
{
|
||||
@ -71,3 +72,9 @@ QString QgsLegendItem::layerID() const
|
||||
{
|
||||
return m_layer->getLayerID();
|
||||
} // layerID
|
||||
|
||||
|
||||
void QgsLegendItem::setOn( bool b )
|
||||
{
|
||||
m_layer->setVisible( b );
|
||||
} // setOn
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/***************************************************************************
|
||||
qgslegenditem.h - description
|
||||
-------------------
|
||||
@ -55,7 +56,7 @@ public:
|
||||
/*! Responds to changes in the layer state (eg. visible vs non visible)
|
||||
*@param v True if layer is visible
|
||||
*/
|
||||
// DEPRECATED? void stateChange(bool v);
|
||||
void stateChange(bool v);
|
||||
|
||||
/*! Gets the layer associated with this legend item
|
||||
* @return Pointer to the layer
|
||||
@ -66,6 +67,9 @@ public:
|
||||
*/
|
||||
QString layerID() const;
|
||||
|
||||
/** sets check box state and consequently the visibility of corresponding map layer */
|
||||
void setOn( bool );
|
||||
|
||||
private: // Private attributes
|
||||
|
||||
/** */
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <iostream>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
#include <qstring.h>
|
||||
#include <qpainter.h>
|
||||
#include <qrect.h>
|
||||
@ -805,7 +807,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
|
||||
|
||||
// create the search rectangle
|
||||
double searchRadius = extent().width() * calculateSearchRadiusValue();
|
||||
QGuardedPtr<QgsRect> search = new QgsRect();
|
||||
QgsRect * search = new QgsRect;
|
||||
// convert screen coordinates to map coordinates
|
||||
QgsPoint idPoint = imp_->coordXForm->toMapCoordinates(e->x(), e->y());
|
||||
search->setXmin(idPoint.x() - searchRadius);
|
||||
|
@ -16,6 +16,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef QGSMAPLAYER_H
|
||||
#define QGSMAPLAYER_H
|
||||
|
||||
@ -23,14 +24,13 @@
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <qobject.h>
|
||||
/* #include "qgsdatasource.h" */
|
||||
#include "qgsrect.h"
|
||||
#include "qgis.h"
|
||||
#include "qgscoordinatetransform.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgssymbol.h"
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include <qgsrect.h>
|
||||
#include <qgis.h>
|
||||
#include <qgscoordinatetransform.h>
|
||||
#include <qgisapp.h>
|
||||
#include <qgssymbol.h>
|
||||
#include <qgsfield.h>
|
||||
|
||||
class QgsFeature;
|
||||
@ -43,81 +43,99 @@ class QgsLegendItem;
|
||||
* This class is the base class for all map layer types (shapefile,
|
||||
* raster, database).
|
||||
*/
|
||||
class QgsMapLayer:public QObject
|
||||
class QgsMapLayer : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/*! Constructor
|
||||
* @param type Type of layer as defined in LAYERS enum
|
||||
* @param lyrname Display Name of the layer
|
||||
*/
|
||||
QgsMapLayer(int type = 0, QString lyrname = QString::null, QString source = QString::null);
|
||||
QgsMapLayer(int type = 0, QString lyrname = QString::null, QString source = QString::null);
|
||||
|
||||
//! Destructor
|
||||
virtual ~ QgsMapLayer();
|
||||
|
||||
/*! Get the type of the layer
|
||||
* @return Integer matching a value in the LAYERS enum
|
||||
*/
|
||||
const int type();
|
||||
|
||||
/*! Get this layer's unique ID */
|
||||
QString getLayerID();
|
||||
|
||||
/*! Set the display name of the layer
|
||||
# @param name New name for the layer
|
||||
*/
|
||||
void setLayerName(const QString & name);
|
||||
|
||||
/*! Get the display name of the layer
|
||||
* @return the layer name
|
||||
*/
|
||||
const QString name();
|
||||
|
||||
/*! Get the internal name of the layer. This is the name used to created the
|
||||
* layer from the data source
|
||||
* @return internal datasource name of the layer
|
||||
*/
|
||||
QString sourceName();
|
||||
|
||||
/*! Virtual function to calculate the extent of the current layer.
|
||||
* This function must be overridden in all child classes and implemented
|
||||
* based on the layer type
|
||||
*/
|
||||
virtual QgsRect calculateExtent();
|
||||
|
||||
virtual void draw(QPainter *, QgsRect *, int);
|
||||
virtual void draw(QPainter *, QgsRect *, QgsCoordinateTransform * cXf, QPaintDevice * src, QPaintDevice * dst);
|
||||
|
||||
/*! Identify the feature(s) in this layer that are contained in the search rectangle
|
||||
*/
|
||||
virtual void identify(QgsRect *)
|
||||
{
|
||||
};
|
||||
|
||||
/*!Select features on the map canvas by dragging a rectangle */
|
||||
virtual void select(QgsRect *, bool lock)
|
||||
{
|
||||
};
|
||||
|
||||
/*! Display the attribute table for the layer
|
||||
*/
|
||||
virtual void table()
|
||||
{
|
||||
};
|
||||
|
||||
/*! Return the extent of the layer as a QRect
|
||||
*/
|
||||
const QgsRect extent();
|
||||
|
||||
/*! Returns the status of the layer. An invalid layer is one which has a bad datasource
|
||||
* or other problem. Child classes set this flag when intialized
|
||||
*@return True if the layer is valid and can be accessed
|
||||
*/
|
||||
bool isValid();
|
||||
|
||||
/** Write property of QString labelField. */
|
||||
virtual void setlabelField(const QString & _newVal);
|
||||
|
||||
/** Read property of QString labelField. */
|
||||
virtual const QString & labelField();
|
||||
|
||||
//! Visibility of the layer
|
||||
bool visible();
|
||||
//! set visibility
|
||||
void setVisible(bool vis);
|
||||
|
||||
//! Returns the source for the layer
|
||||
QString source();
|
||||
|
||||
/** Write property of int featureType. */
|
||||
virtual void setFeatureType(const int &_newVal);
|
||||
|
||||
/** Read property of int featureType. */
|
||||
virtual const int &featureType();
|
||||
|
||||
/** Return the context menu for the layer */
|
||||
virtual QPopupMenu *contextMenu() = 0;
|
||||
|
||||
@ -125,27 +143,27 @@ class QgsMapLayer:public QObject
|
||||
* Get the first feature resulting from a select operation
|
||||
* @return QgsFeature
|
||||
*/
|
||||
virtual QgsFeature * getFirstFeature(bool fetchAttributes=false) const;
|
||||
virtual QgsFeature *getFirstFeature(bool fetchAttributes = false) const;
|
||||
|
||||
/**
|
||||
* Get the next feature resulting from a select operation
|
||||
* @return QgsFeature
|
||||
*/
|
||||
virtual QgsFeature * getNextFeature(bool fetchAttributes=false) const;
|
||||
virtual QgsFeature *getNextFeature(bool fetchAttributes = false) const;
|
||||
|
||||
/**
|
||||
* Get the next feature using new method
|
||||
* TODO - make this pure virtual once it works and change existing providers
|
||||
* to use this method of fetching features
|
||||
*/
|
||||
virtual bool getNextFeature(QgsFeature &feature, bool fetchAttributes=false) const;
|
||||
virtual bool getNextFeature(QgsFeature & feature, bool fetchAttributes = false) const;
|
||||
|
||||
/**
|
||||
* Number of features in the layer
|
||||
* @return long containing number of features
|
||||
*/
|
||||
virtual long featureCount() const;
|
||||
|
||||
|
||||
/**
|
||||
Number of attribute fields for a feature in the layer
|
||||
@note
|
||||
@ -159,7 +177,7 @@ class QgsMapLayer:public QObject
|
||||
Return a list of field names for this layer
|
||||
@return vector of field names
|
||||
*/
|
||||
virtual std::vector<QgsField> const & fields() const;
|
||||
virtual std::vector < QgsField > const &fields() const;
|
||||
|
||||
|
||||
//! Layers enum defining the types of layers that can be added to a map
|
||||
@ -169,63 +187,90 @@ class QgsMapLayer:public QObject
|
||||
RASTER,
|
||||
DATABASE
|
||||
};
|
||||
|
||||
/**Shows the properties dialog for the map layer*/
|
||||
virtual void showLayerProperties() = 0;
|
||||
|
||||
/**Returns a pointer to the legend pixmap*/
|
||||
virtual QPixmap *legendPixmap();
|
||||
/** All inherited layers must be able to display a conext menu if requested */
|
||||
|
||||
/** All inherited layers must be able to display a conext menu if requested */
|
||||
virtual void initContextMenu(QgisApp * app) = 0;
|
||||
|
||||
/**Returns a pointer to the legend item*/
|
||||
QgsLegendItem *legendItem();
|
||||
|
||||
/**Sets the pointer to the legend item*/
|
||||
void setLegendItem(QgsLegendItem * li);
|
||||
|
||||
public slots:
|
||||
|
||||
//! set visibility
|
||||
void setVisible(bool vis);
|
||||
|
||||
signals:
|
||||
|
||||
void visibilityChanged(void);
|
||||
/** \brief emit a signal to notify of a progress event */
|
||||
void setProgress(int theProgress, int theTotalSteps);
|
||||
/** \brief emit a signal to be caught by gisapp and display a msg on status bar */
|
||||
void setStatus(QString theStatusQString);
|
||||
void visibilityChanged(void);
|
||||
|
||||
/** \brief emit a signal to notify of a progress event */
|
||||
void setProgress(int theProgress, int theTotalSteps);
|
||||
|
||||
/** \brief emit a signal to be caught by gisapp and display a msg on status bar */
|
||||
void setStatus(QString theStatusQString);
|
||||
|
||||
/** This signal should be connected with the slot QgsMapCanvas::refresh() */
|
||||
virtual void repaintRequested();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//! Extent of the layer
|
||||
QgsRect layerExtent;
|
||||
|
||||
//! Indicates if the layer is valid and can be drawn
|
||||
bool valid;
|
||||
|
||||
//! data source description string, varies by layer type
|
||||
QString dataSource;
|
||||
|
||||
//! Geometry type as defined in enum WKBTYPE (qgis.h)
|
||||
int geometryType;
|
||||
|
||||
/**Pointer to the legend item for this layer*/
|
||||
QgsLegendItem *m_legendItem;
|
||||
|
||||
/**Pixmap used in the legend item*/
|
||||
QPixmap m_legendPixmap;
|
||||
|
||||
/** Name of the layer - used for display */
|
||||
QString layerName;
|
||||
|
||||
/** Internal name of the layer. Derived from the datasource */
|
||||
QString internalName;
|
||||
|
||||
//! context menu
|
||||
QPopupMenu *popMenu;
|
||||
|
||||
private: // Private attributes
|
||||
|
||||
/** Unique ID of this layer - used to refer to this layer in QGIS code */
|
||||
QString ID;
|
||||
|
||||
/** Type of the layer (eg. vector, raster, database */
|
||||
int layerType;
|
||||
|
||||
//! Tag for embedding additional information
|
||||
QString tag;
|
||||
|
||||
/** true if visible ? */
|
||||
bool m_visible;
|
||||
/** */
|
||||
|
||||
|
||||
public: // Public attributes
|
||||
/** */
|
||||
|
||||
/** map label ? */
|
||||
QString m_labelField;
|
||||
|
||||
signals:
|
||||
/**This signal should be connected with the slot QgsMapCanvas::refresh()*/
|
||||
virtual void repaintRequested();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user