mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
[UPDATE] remove "layer file" items in legend - feature that was added long time ago but never actually worked well :-)
Hopefully it doesn't break anything... git-svn-id: http://svn.osgeo.org/qgis/trunk@12035 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9ad21f7c29
commit
6c8f0f89a7
@ -88,8 +88,6 @@ SET(QGIS_APP_SRCS
|
||||
legend/qgslegend.cpp
|
||||
legend/qgslegenditem.cpp
|
||||
legend/qgslegendlayer.cpp
|
||||
legend/qgslegendlayerfile.cpp
|
||||
legend/qgslegendlayerfilegroup.cpp
|
||||
legend/qgslegendpropertygroup.cpp
|
||||
legend/qgslegendpropertyitem.cpp
|
||||
legend/qgslegendsymbologygroup.cpp
|
||||
@ -184,7 +182,6 @@ SET (QGIS_APP_MOC_HDRS
|
||||
|
||||
legend/qgslegend.h
|
||||
legend/qgslegendlayer.h
|
||||
legend/qgslegendlayerfile.h
|
||||
|
||||
ogr/qgsopenvectorlayerdialog.h
|
||||
ogr/qgsnewogrconnection.h
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,11 +26,11 @@
|
||||
#include <QTreeWidget>
|
||||
|
||||
class QgsLegendLayer;
|
||||
class QgsLegendLayerFile;
|
||||
class QgsLegendItem;
|
||||
class QgsMapLayer;
|
||||
class QgsMapCanvas;
|
||||
class QDomDocument;
|
||||
class QDomElement;
|
||||
class QDomNode;
|
||||
class QMouseEvent;
|
||||
class QTreeWidgetItem;
|
||||
@ -69,12 +69,6 @@ class QTreeWidgetItem;
|
||||
<li>QgsLegendPropertyItem - A list of properties related to the layer. Double clicking
|
||||
a property item will invoke a dialog that will let you change
|
||||
the property settings. Can only exist inside a property group</li>
|
||||
<li>QgsLegendLayerFileGroup - each QgsLegendLayer can have one or more files associated
|
||||
with it. This is the container group for these files. Can
|
||||
only exist inside of a QgsLegendLayer.</li>
|
||||
<li>QgsLegendLayerFile - A file node that relates to a file on disk. Assigning multiple
|
||||
file nodes in a file group allows you treat them as if they are
|
||||
one entity.</li>
|
||||
</ul>
|
||||
@note Additional group types may be defined in the future to accommodate WMS, PostGIS etc layers.
|
||||
@author Gary E.Sherman, Tim Sutton, Marco Hugentobler and Jens Oberender
|
||||
@ -101,10 +95,10 @@ class QgsLegend : public QTreeWidget
|
||||
//! Destructor
|
||||
~QgsLegend();
|
||||
|
||||
/** Returns QgsLegendLayerFile associated with current layer */
|
||||
QgsLegendLayerFile* currentLayerFile();
|
||||
/** Returns QgsLegendLayer associated with current layer */
|
||||
QgsLegendLayer* currentLegendLayer();
|
||||
|
||||
/*!Returns the current layer if the current item is a QgsLegendLayerFile.
|
||||
/*!Returns the current layer if the current item is a QgsLegendLayer.
|
||||
If the current item is a QgsLegendLayer, its first maplayer is returned.
|
||||
Else, 0 is returned.*/
|
||||
QgsMapLayer* currentLayer();
|
||||
@ -168,10 +162,6 @@ class QgsLegend : public QTreeWidget
|
||||
/**Removes an entry from mPixmapHeightValues*/
|
||||
void removePixmapHeightValue( int height );
|
||||
|
||||
/** Sets the name of the QgsLegendLayer that is the parent of
|
||||
the given QgsLegendLayerFile */
|
||||
void setName( QgsLegendLayerFile* w, QString layerName );
|
||||
|
||||
/**Sets the toggle editing action. Usually called from QgisApp*/
|
||||
void setToggleEditingAction( QAction* editingAction ) {mToggleEditingAction = editingAction;}
|
||||
|
||||
@ -219,7 +209,7 @@ class QgsLegend : public QTreeWidget
|
||||
/** called to write legend settings to project */
|
||||
void writeProject( QDomDocument & );
|
||||
|
||||
/**Removes the current LegendLayer and all its LegendLayerFiles*/
|
||||
/**Removes the current LegendLayer*/
|
||||
void legendLayerRemove();
|
||||
|
||||
/**Removes a layer. If the layer is editable, a dialog is shown where user can select 'save', 'discard' and optionally 'cancel'. Cancel
|
||||
@ -332,6 +322,9 @@ class QgsLegend : public QTreeWidget
|
||||
/** Returns the last visible item in the tree widget */
|
||||
QTreeWidgetItem *lastVisibleItem();
|
||||
|
||||
/** read layer settings from XML element and add item */
|
||||
QgsLegendLayer* readLayerFromXML(QDomElement& childelem, bool& isOpen);
|
||||
|
||||
private slots:
|
||||
|
||||
/**Calls 'handleRightClickEvent' on the item*/
|
||||
@ -350,8 +343,6 @@ class QgsLegend : public QTreeWidget
|
||||
void openEditor();
|
||||
/**Removes the current item and inserts it as a toplevel item at the end of the legend*/
|
||||
void makeToTopLevelItem();
|
||||
/**Show/ Hide the legend layer file groups*/
|
||||
void showLegendLayerFileGroups();
|
||||
|
||||
private:
|
||||
|
||||
@ -396,8 +387,6 @@ class QgsLegend : public QTreeWidget
|
||||
HIERARCHY_POSITION_TYPE mRestoreInformation;
|
||||
QTreeWidgetItem* mRestoreItem;
|
||||
|
||||
bool mShowLegendLayerFiles;
|
||||
|
||||
/**Stores the layer ordering before a mouse Move. After the move, this is used to
|
||||
decide if the mapcanvas really has to be refreshed*/
|
||||
std::deque<QString> mLayersPriorToMove;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "qgisapp.h"
|
||||
#include "qgslegendgroup.h"
|
||||
#include "qgslegendlayer.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QIcon>
|
||||
|
||||
@ -96,7 +95,7 @@ QgsLegendItem::DRAG_ACTION QgsLegendGroup::accept( const QgsLegendItem* li ) con
|
||||
return NO_ACTION;
|
||||
}
|
||||
|
||||
bool QgsLegendGroup::insert( QgsLegendItem* theItem )
|
||||
/*bool QgsLegendGroup::insert( QgsLegendItem* theItem )
|
||||
{
|
||||
if ( theItem->type() == LEGEND_LAYER )
|
||||
{
|
||||
@ -106,18 +105,17 @@ bool QgsLegendGroup::insert( QgsLegendItem* theItem )
|
||||
// XXX - mloskot - I don't know what to return
|
||||
// but this function must return a value
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
std::list<QgsLegendLayerFile*> QgsLegendGroup::legendLayerFiles()
|
||||
std::list<QgsLegendLayer*> QgsLegendGroup::legendLayers()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> result;
|
||||
std::list<QgsLegendLayer*> result;
|
||||
for ( int i = 0; i < childCount(); ++i )
|
||||
{
|
||||
QgsLegendLayer* childItem = dynamic_cast<QgsLegendLayer *>( child( i ) );
|
||||
if ( childItem )
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> childList = childItem->legendLayerFiles();
|
||||
result.splice( result.end(), childList );
|
||||
result.push_back(childItem);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -125,15 +123,15 @@ std::list<QgsLegendLayerFile*> QgsLegendGroup::legendLayerFiles()
|
||||
|
||||
void QgsLegendGroup::updateCheckState()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> llfiles = legendLayerFiles();
|
||||
if ( llfiles.size() < 1 )
|
||||
std::list<QgsLegendLayer*> llayers = legendLayers();
|
||||
if ( llayers.size() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<QgsLegendLayerFile*>::iterator iter = llfiles.begin();
|
||||
std::list<QgsLegendLayer*>::iterator iter = llayers.begin();
|
||||
Qt::CheckState theState = ( *iter )->checkState( 0 );
|
||||
for ( ; iter != llfiles.end(); ++iter )
|
||||
for ( ; iter != llayers.end(); ++iter )
|
||||
{
|
||||
if ( theState != ( *iter )->checkState( 0 ) )
|
||||
{
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <list>
|
||||
#include <qgslegenditem.h>
|
||||
|
||||
class QgsLegendLayerFile;
|
||||
|
||||
/**
|
||||
This is a specialised version of QLegendItem that specifies that the items below this point will be treated as a group. For example hiding this node will hide all layers below that are members of the group.
|
||||
@ -41,10 +40,10 @@ class QgsLegendGroup : public QgsLegendItem
|
||||
QgsLegendItem::DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
|
||||
QgsLegendItem::DRAG_ACTION accept( const QgsLegendItem* li ) const;
|
||||
bool isLeafNode();
|
||||
bool insert( QgsLegendItem* theItem );
|
||||
/**Returns all legend layer files under this group*/
|
||||
std::list<QgsLegendLayerFile*> legendLayerFiles();
|
||||
/**Goes through all the legendlayerfiles and sets check state to checked/partially checked/unchecked*/
|
||||
//bool insert( QgsLegendItem* theItem );
|
||||
/**Returns all legend layers under this group*/
|
||||
std::list<QgsLegendLayer*> legendLayers();
|
||||
/**Goes through all the legendlayers and sets check state to checked/partially checked/unchecked*/
|
||||
void updateCheckState();
|
||||
};
|
||||
|
||||
|
@ -66,7 +66,6 @@ class QgsLegendItem : public QTreeWidgetItem, public QObject
|
||||
|
||||
virtual bool isLeafNode() = 0;
|
||||
virtual LEGEND_ITEM_TYPE type() const {return mType;}
|
||||
virtual void addItem( QgsLegendItem* ) {}
|
||||
/**Returns the type of action that will be done if a drag, originating at a certain
|
||||
item type, will be released at this item*/
|
||||
virtual DRAG_ACTION accept( LEGEND_ITEM_TYPE type ) = 0;
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "qgisapp.h"
|
||||
#include "qgslegend.h"
|
||||
#include "qgslegendlayer.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgslegendlayerfilegroup.h"
|
||||
#include "qgslegendsymbologyitem.h"
|
||||
#include "qgslogger.h"
|
||||
|
||||
@ -35,6 +33,10 @@
|
||||
#include "qgssymbol.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsvectorfilewriter.h"
|
||||
#include "qgsgenericprojectionselector.h"
|
||||
#include "qgsattributetabledialog.h"
|
||||
#include "qgsencodingfiledialog.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QAction>
|
||||
@ -45,32 +47,39 @@
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
QgsLegendLayer::QgsLegendLayer( QTreeWidgetItem* parent, QString name )
|
||||
: QgsLegendItem( parent, name )
|
||||
{
|
||||
mType = LEGEND_LAYER;
|
||||
setFlags( Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
setCheckState( 0, Qt::Checked );
|
||||
setText( 0, name );
|
||||
setupFont();
|
||||
}
|
||||
|
||||
QgsLegendLayer::QgsLegendLayer( QTreeWidget* parent, QString name ): QgsLegendItem( parent, name )
|
||||
QgsLegendLayer::QgsLegendLayer( QgsMapLayer* layer )
|
||||
: QgsLegendItem( ),
|
||||
mLyr( layer )
|
||||
{
|
||||
mType = LEGEND_LAYER;
|
||||
setFlags( Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
setCheckState( 0, Qt::Checked );
|
||||
setText( 0, name );
|
||||
setText( 0, layer->name() );
|
||||
setupFont();
|
||||
}
|
||||
|
||||
QgsLegendLayer::QgsLegendLayer( QString name ): QgsLegendItem()
|
||||
{
|
||||
mType = LEGEND_LAYER;
|
||||
setFlags( Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
setCheckState( 0, Qt::Checked );
|
||||
setText( 0, name );
|
||||
setupFont();
|
||||
// Set the initial visibility flag for layers
|
||||
// This user option allows the user to turn off initial drawing of
|
||||
// layers when they are added to the map. This is useful when adding
|
||||
// many layers and the user wants to adjusty symbology, etc prior to
|
||||
// actually viewing the layer.
|
||||
QSettings settings;
|
||||
bool visible = settings.value( "/qgis/new_layers_visible", true ).toBool();
|
||||
mLyr.setVisible( visible );
|
||||
|
||||
// not in overview by default
|
||||
mLyr.setInOverview( FALSE );
|
||||
|
||||
// Add check if vector layer when connecting to selectionChanged slot
|
||||
// Ticket #811 - racicot
|
||||
QgsMapLayer *currentLayer = mLyr.layer();
|
||||
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
|
||||
if ( isVectLyr )
|
||||
{
|
||||
connect( mLyr.layer(), SIGNAL( editingStarted() ), this, SLOT( updateLegendItem() ) );
|
||||
connect( mLyr.layer(), SIGNAL( editingStopped() ), this, SLOT( updateLegendItem() ) );
|
||||
}
|
||||
connect( mLyr.layer(), SIGNAL( layerNameChanged() ), this, SLOT( layerNameChanged() ) );
|
||||
}
|
||||
|
||||
QgsLegendLayer::~QgsLegendLayer()
|
||||
@ -126,133 +135,10 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayer::accept( const QgsLegendItem* li ) con
|
||||
return NO_ACTION;
|
||||
}
|
||||
|
||||
QgsLegendLayerFile* QgsLegendLayer::firstLayerFile() const
|
||||
|
||||
QgsMapLayer* QgsLegendLayer::layer()
|
||||
{
|
||||
//first find the legend layer file group
|
||||
QgsLegendLayerFileGroup* llfg = 0;
|
||||
for ( int i = 0; i < childCount(); ++i )
|
||||
{
|
||||
llfg = dynamic_cast<QgsLegendLayerFileGroup *>( child( i ) );
|
||||
if ( llfg )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !llfg )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QTreeWidgetItem* llf = llfg->child( 0 );
|
||||
if ( !llf )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
QgsLegendLayerFile* legendlayerfile = dynamic_cast<QgsLegendLayerFile *>( llf );
|
||||
return legendlayerfile;
|
||||
}
|
||||
|
||||
QgsMapLayer* QgsLegendLayer::firstMapLayer() const
|
||||
{
|
||||
QgsLegendLayerFile* llf = firstLayerFile();
|
||||
if ( llf )
|
||||
{
|
||||
return llf->layer();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<QgsMapLayer*> QgsLegendLayer::mapLayers()
|
||||
{
|
||||
std::list<QgsMapLayer*> list;
|
||||
std::list<QgsLegendLayerFile*> llist = legendLayerFiles();
|
||||
for ( std::list<QgsLegendLayerFile*>::iterator it = llist.begin(); it != llist.end(); ++it )
|
||||
{
|
||||
list.push_back(( *it )->layer() );
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
std::list<QgsLegendLayerFile*> QgsLegendLayer::legendLayerFiles()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> list;
|
||||
|
||||
//find the layer file group
|
||||
QgsLegendLayerFileGroup* theLayerGroup = 0;
|
||||
for ( int i = 0; i < childCount(); ++i )
|
||||
{
|
||||
theLayerGroup = dynamic_cast<QgsLegendLayerFileGroup *>( child( i ) );
|
||||
if ( theLayerGroup )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//add all the legend layer files in the group
|
||||
if ( theLayerGroup )
|
||||
{
|
||||
QgsLegendLayerFile* theFile = 0;
|
||||
for ( int i = 0; i < theLayerGroup->childCount(); ++i )
|
||||
{
|
||||
theFile = dynamic_cast<QgsLegendLayerFile *>( theLayerGroup->child( i ) );
|
||||
if ( theFile )
|
||||
{
|
||||
list.push_back( theFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void QgsLegendLayer::updateLayerSymbologySettings( const QgsMapLayer* mapLayer )
|
||||
{
|
||||
if ( mapLayer )
|
||||
{
|
||||
//find all layers
|
||||
std::list<QgsMapLayer*> theMapLayers = mapLayers();
|
||||
for ( std::list<QgsMapLayer*>::iterator it = theMapLayers.begin(); it != theMapLayers.end(); ++it )
|
||||
{
|
||||
if (( *it ) != mapLayer )
|
||||
{
|
||||
( *it )->copySymbologySettings( *mapLayer );
|
||||
}
|
||||
}
|
||||
// source might have changed - e.g. other subset
|
||||
setToolTip( 0, mapLayer->publicSource() );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLegendLayer::updateCheckState()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> llfiles = legendLayerFiles();
|
||||
if ( llfiles.size() < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ( theState != checkState( 0 ) )
|
||||
{
|
||||
treeWidget()->blockSignals( true );
|
||||
setCheckState( 0, theState );
|
||||
//notify the legend that the check state has changed
|
||||
legend()->updateCheckStates( this, theState );
|
||||
treeWidget()->blockSignals( false );
|
||||
}
|
||||
return mLyr.layer();
|
||||
}
|
||||
|
||||
void QgsLegendLayer::refreshSymbology( const QString& key, double widthScale )
|
||||
@ -307,9 +193,6 @@ void QgsLegendLayer::changeSymbologySettings( const QgsMapLayer* theMapLayer,
|
||||
++childposition;
|
||||
}
|
||||
|
||||
//copy the legend settings for the other layer files in the same legend layer
|
||||
updateLayerSymbologySettings( theMapLayer );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -401,48 +284,48 @@ void QgsLegendLayer::updateIcon()
|
||||
{
|
||||
QPixmap newIcon( getOriginalPixmap() );
|
||||
|
||||
QgsMapLayer* theLayer = firstMapLayer();
|
||||
QgsMapLayer* theLayer = layer();
|
||||
|
||||
if ( mapLayers().size() == 1 )
|
||||
//overview
|
||||
// FIXME: overview icon is missing
|
||||
/*
|
||||
if ( theFile->isInOverview() )
|
||||
{
|
||||
//overview
|
||||
// FIXME: overview icon is missing
|
||||
/*
|
||||
if ( theFile->isInOverview() )
|
||||
{
|
||||
// Overlay the overview icon on the default icon
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconOverview.png" );
|
||||
QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();
|
||||
}*/
|
||||
// Overlay the overview icon on the default icon
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconOverview.png" );
|
||||
QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();
|
||||
}*/
|
||||
|
||||
//editable
|
||||
if ( theLayer->isEditable() )
|
||||
{
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconEditable.png" );
|
||||
// use editable icon instead of the layer's type icon
|
||||
newIcon = myPixmap;
|
||||
//editable
|
||||
if ( theLayer->isEditable() )
|
||||
{
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconEditable.png" );
|
||||
// use editable icon instead of the layer's type icon
|
||||
newIcon = myPixmap;
|
||||
|
||||
// Overlay the editable icon on the default icon
|
||||
/*QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();*/
|
||||
}
|
||||
// Overlay the editable icon on the default icon
|
||||
/*QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();*/
|
||||
}
|
||||
|
||||
// TODO: projection error icon?
|
||||
|
||||
QIcon theIcon( newIcon );
|
||||
setIcon( 0, theIcon );
|
||||
}
|
||||
|
||||
QPixmap QgsLegendLayer::getOriginalPixmap() const
|
||||
QPixmap QgsLegendLayer::getOriginalPixmap()
|
||||
{
|
||||
QgsMapLayer* firstLayer = firstMapLayer();
|
||||
if ( firstLayer )
|
||||
QgsMapLayer* theLayer = layer();
|
||||
if ( theLayer )
|
||||
{
|
||||
if ( firstLayer->type() == QgsMapLayer::VectorLayer )
|
||||
|
||||
if ( theLayer->type() == QgsMapLayer::VectorLayer )
|
||||
{
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( firstLayer );
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( theLayer );
|
||||
switch ( vlayer->geometryType() )
|
||||
{
|
||||
case QGis::Point:
|
||||
@ -458,9 +341,9 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
|
||||
return QgisApp::getThemePixmap( "/mIconLayer.png" );
|
||||
}
|
||||
}
|
||||
else if ( firstLayer->type() == QgsMapLayer::RasterLayer )
|
||||
else if ( theLayer->type() == QgsMapLayer::RasterLayer )
|
||||
{
|
||||
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( firstLayer );
|
||||
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( theLayer );
|
||||
QPixmap myPixmap( 32, 32 );
|
||||
rlayer->thumbnailAsPixmap( &myPixmap );
|
||||
return myPixmap;
|
||||
@ -473,25 +356,23 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
|
||||
|
||||
void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction )
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> files = legendLayerFiles();
|
||||
QgsMapLayer* firstLayer = NULL;
|
||||
if ( files.size() > 0 )
|
||||
{
|
||||
firstLayer = files.front()->layer();
|
||||
}
|
||||
|
||||
QgsMapLayer* lyr = layer();
|
||||
|
||||
// zoom to layer extent
|
||||
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
|
||||
tr( "&Zoom to layer extent" ), legend(), SLOT( legendLayerZoom() ) );
|
||||
if ( firstLayer && firstLayer->type() == QgsMapLayer::RasterLayer )
|
||||
if ( lyr->type() == QgsMapLayer::RasterLayer )
|
||||
{
|
||||
theMenu.addAction( tr( "&Zoom to best scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );
|
||||
}
|
||||
|
||||
// show in overview
|
||||
QAction* showInOverviewAction = theMenu.addAction( tr( "&Show in overview" ), this, SLOT( showInOverview() ) );
|
||||
showInOverviewAction->setCheckable( true ); // doesn't support tristate
|
||||
showInOverviewAction->setChecked( isInOverview() );
|
||||
showInOverviewAction->setCheckable( true );
|
||||
showInOverviewAction->blockSignals( true );
|
||||
showInOverviewAction->setChecked( mLyr.isInOverview() );
|
||||
showInOverviewAction->blockSignals( false );
|
||||
|
||||
// remove from canvas
|
||||
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemove.png" ),
|
||||
@ -499,42 +380,30 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
|
||||
|
||||
theMenu.addSeparator();
|
||||
|
||||
if ( firstLayer && firstLayer->type() == QgsMapLayer::VectorLayer )
|
||||
if ( lyr->type() == QgsMapLayer::VectorLayer )
|
||||
{
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
|
||||
|
||||
// attribute table
|
||||
QAction* tableAction = theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
|
||||
if ( files.size() != 1 )
|
||||
{
|
||||
tableAction->setEnabled( false );
|
||||
}
|
||||
|
||||
// allow editing
|
||||
if ( toggleEditingAction )
|
||||
int cap = vlayer->dataProvider()->capabilities();
|
||||
if ( cap & QgsVectorDataProvider::EditingCapabilities )
|
||||
{
|
||||
theMenu.addAction( toggleEditingAction );
|
||||
}
|
||||
|
||||
QgsVectorLayer* mypVectorLayer = qobject_cast<QgsVectorLayer *>( firstLayer );
|
||||
|
||||
if ( files.size() != 1 )
|
||||
{
|
||||
toggleEditingAction->setEnabled( false );
|
||||
}
|
||||
if ( mypVectorLayer )
|
||||
{
|
||||
toggleEditingAction->setChecked( mypVectorLayer->isEditable() );
|
||||
if ( toggleEditingAction )
|
||||
{
|
||||
theMenu.addAction( toggleEditingAction );
|
||||
toggleEditingAction->setChecked( vlayer->isEditable() );
|
||||
}
|
||||
}
|
||||
|
||||
// save as shapefile
|
||||
QAction* saveShpAction = theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
|
||||
if ( files.size() != 1 )
|
||||
{
|
||||
saveShpAction->setEnabled( false );
|
||||
}
|
||||
|
||||
// save selection as shapefile
|
||||
QAction* saveSelectionAction = theMenu.addAction( tr( "Save selection as shapefile..." ), this, SLOT( saveSelectionAsShapefile() ) );
|
||||
if ( files.size() != 1 || mypVectorLayer->selectedFeatureCount() == 0 )
|
||||
if ( vlayer->selectedFeatureCount() == 0 )
|
||||
{
|
||||
saveSelectionAction->setEnabled( false );
|
||||
}
|
||||
@ -542,79 +411,212 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
|
||||
theMenu.addSeparator();
|
||||
}
|
||||
|
||||
// properties goes on bottom of menu for consistency with normal ui standards
|
||||
// e.g. kde stuff
|
||||
theMenu.addAction( tr( "&Properties" ), legend(), SLOT( legendLayerShowProperties() ) );
|
||||
|
||||
QAction* propertiesAction = theMenu.addAction( tr( "&Properties" ), legend(), SLOT( legendLayerShowProperties() ) );
|
||||
if ( files.size() != 1 )
|
||||
{
|
||||
propertiesAction->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLegendLayer::table()
|
||||
{
|
||||
QgsVectorLayer * myLayer = qobject_cast<QgsVectorLayer *>( mLyr.layer() );
|
||||
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer );
|
||||
mDialog->show();
|
||||
// the dialog will be deleted by itself on close
|
||||
}
|
||||
|
||||
void QgsLegendLayer::saveAsShapefile()
|
||||
{
|
||||
saveAsShapefileGeneral( FALSE );
|
||||
}
|
||||
|
||||
void QgsLegendLayer::saveSelectionAsShapefile()
|
||||
{
|
||||
saveAsShapefileGeneral( TRUE );
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
void QgsLegendLayer::setVisible( bool visible )
|
||||
{
|
||||
mLyr.setVisible( visible );
|
||||
}
|
||||
|
||||
bool QgsLegendLayer::isVisible()
|
||||
{
|
||||
return mLyr.isVisible();
|
||||
}
|
||||
|
||||
|
||||
void QgsLegendLayer::setInOverview( bool isInOverview )
|
||||
{
|
||||
mLyr.setInOverview( isInOverview );
|
||||
}
|
||||
|
||||
bool QgsLegendLayer::isInOverview()
|
||||
{
|
||||
// QAction doesn't support tristate checkboxes
|
||||
// returns true if just some are in overview
|
||||
bool hasVisible = false;
|
||||
|
||||
// find out whether we're showing or hiding them
|
||||
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
|
||||
for ( std::list<QgsLegendLayerFile*>::iterator it = maplayers.begin(); it != maplayers.end(); ++it )
|
||||
{
|
||||
if ( *it && ( *it )->isInOverview() )
|
||||
{
|
||||
hasVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return hasVisible;
|
||||
return mLyr.isInOverview();
|
||||
}
|
||||
|
||||
void QgsLegendLayer::showInOverview()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
|
||||
bool showLayers = ( ! isInOverview() );
|
||||
|
||||
// set overview visibility
|
||||
for ( std::list<QgsLegendLayerFile*>::iterator it = maplayers.begin(); it != maplayers.end(); ++it )
|
||||
{
|
||||
if ( *it )
|
||||
( *it )->setInOverview( showLayers );
|
||||
}
|
||||
// toggle current status
|
||||
setInOverview( ! isInOverview() );
|
||||
|
||||
legend()->updateMapCanvasLayerSet();
|
||||
legend()->updateOverview();
|
||||
}
|
||||
|
||||
void QgsLegendLayer::table()
|
||||
|
||||
|
||||
|
||||
void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
|
||||
if ( maplayers.size() > 1 )
|
||||
QgsCoordinateReferenceSystem destCRS;
|
||||
|
||||
if ( mLyr.layer()->type() != QgsMapLayer::VectorLayer )
|
||||
return;
|
||||
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mLyr.layer() );
|
||||
|
||||
// get a name for the shapefile
|
||||
// Get a file to process, starting at the current directory
|
||||
QSettings settings;
|
||||
QString filter = QString( "Shapefiles (*.shp)" );
|
||||
QString dirName = settings.value( "/UI/lastShapefileDir", "." ).toString();
|
||||
|
||||
QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( 0,
|
||||
tr( "Save layer as..." ),
|
||||
dirName,
|
||||
filter,
|
||||
QString( "" ) );
|
||||
openFileDialog->setAcceptMode( QFileDialog::AcceptSave );
|
||||
|
||||
// allow for selection of more than one file
|
||||
//openFileDialog->setMode(QFileDialog::AnyFile);
|
||||
|
||||
if ( openFileDialog->exec() != QDialog::Accepted )
|
||||
return;
|
||||
|
||||
|
||||
QString encoding = openFileDialog->encoding();
|
||||
QString shapefileName = openFileDialog->selectedFiles().first();
|
||||
settings.setValue( "/UI/lastShapefileDir", QFileInfo( shapefileName ).absolutePath() );
|
||||
|
||||
|
||||
if ( shapefileName.isNull() )
|
||||
return;
|
||||
|
||||
// add the extension if not present
|
||||
if ( shapefileName.indexOf( ".shp" ) == -1 )
|
||||
{
|
||||
QMessageBox::information( 0, tr( "Multiple layers" ),
|
||||
tr( "This item contains multiple layers. Displaying multiple layers in the table is not supported." ) );
|
||||
shapefileName += ".shp";
|
||||
}
|
||||
else if ( maplayers.size() == 1 )
|
||||
|
||||
destCRS = vlayer->srs();
|
||||
// Find out if we have projections enabled or not
|
||||
if ( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() )
|
||||
{
|
||||
maplayers.front()->table();
|
||||
destCRS = QgisApp::instance()->mapCanvas()->mapRenderer()->destinationSrs();
|
||||
}
|
||||
|
||||
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
|
||||
mySelector->setSelectedCrsId( destCRS.srsid() );
|
||||
mySelector->setMessage( tr( "Select the coordinate reference system for the saved shapefile. "
|
||||
"The data points will be transformed from the layer coordinate reference system." ) );
|
||||
|
||||
if ( mySelector->exec() )
|
||||
{
|
||||
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
destCRS = srs;
|
||||
// destCRS->createFromId(mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Aborted CS selection, don't save.
|
||||
delete mySelector;
|
||||
return;
|
||||
}
|
||||
|
||||
delete mySelector;
|
||||
|
||||
// overwrite the file - user will already have been prompted
|
||||
// to verify they want to overwrite by the file dialog above
|
||||
if ( QFile::exists( shapefileName ) )
|
||||
{
|
||||
if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ok if the file existed it should be deleted now so we can continue...
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
QgsVectorFileWriter::WriterError error;
|
||||
error = QgsVectorFileWriter::writeAsShapefile( vlayer, shapefileName, encoding, &destCRS, saveOnlySelection );
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
switch ( error )
|
||||
{
|
||||
case QgsVectorFileWriter::NoError:
|
||||
QMessageBox::information( 0, tr( "Saving done" ), tr( "Export to Shapefile has been completed" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrDriverNotFound:
|
||||
QMessageBox::warning( 0, tr( "Driver not found" ), tr( "ESRI Shapefile driver is not available" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrCreateDataSource:
|
||||
QMessageBox::warning( 0, tr( "Error creating shapefile" ),
|
||||
tr( "The shapefile could not be created (%1)" ).arg( shapefileName ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrCreateLayer:
|
||||
QMessageBox::warning( 0, tr( "Error" ), tr( "Layer creation failed" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrAttributeTypeUnsupported:
|
||||
QMessageBox::warning( 0, tr( "Error" ),
|
||||
tr( "Layer attribute table contains unsupported datatype(s)" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrAttributeCreationFailed:
|
||||
QMessageBox::warning( 0, tr( "Error" ),
|
||||
tr( "Creation of an attribute failed" ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLegendLayer::saveAsShapefile()
|
||||
|
||||
|
||||
QString QgsLegendLayer::nameFromLayer( QgsMapLayer* layer )
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
|
||||
if ( maplayers.size() == 1 )
|
||||
QString sourcename = layer->publicSource(); //todo: move this duplicated code into a new function
|
||||
if ( sourcename.startsWith( "host", Qt::CaseInsensitive ) )
|
||||
{
|
||||
maplayers.front()->saveAsShapefile();
|
||||
//this layer is a database layer
|
||||
//modify source string such that password is not visible
|
||||
sourcename = layer->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
//modify source name such that only the file is visible
|
||||
sourcename = layer->publicSource().section( '/', -1, -1 );
|
||||
}
|
||||
return sourcename;
|
||||
}
|
||||
|
||||
void QgsLegendLayer::saveSelectionAsShapefile()
|
||||
|
||||
QgsMapCanvasLayer& QgsLegendLayer::canvasLayer()
|
||||
{
|
||||
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
|
||||
if ( maplayers.size() == 1 )
|
||||
{
|
||||
maplayers.front()->saveSelectionAsShapefile();
|
||||
}
|
||||
return mLyr;
|
||||
}
|
||||
|
||||
void QgsLegendLayer::layerNameChanged()
|
||||
{
|
||||
QString name = mLyr.layer()->name();
|
||||
setText( 0, name );
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,12 @@
|
||||
#ifndef QGSLEGENDLAYER_H
|
||||
#define QGSLEGENDLAYER_H
|
||||
|
||||
//#include <qobject.h>
|
||||
#include <qgslegenditem.h>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
class QgsLegendLayer;
|
||||
class QgsLegendLayerFile;
|
||||
class QgsLegendPropertyGroup;
|
||||
class QgsMapLayer;
|
||||
class QgsRasterLayer;
|
||||
@ -45,25 +45,17 @@ class QgsLegendLayer : public QgsLegendItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsLegendLayer( QTreeWidgetItem *, QString );
|
||||
QgsLegendLayer( QTreeWidget*, QString );
|
||||
QgsLegendLayer( QString name );
|
||||
QgsLegendLayer( QgsMapLayer* layer );
|
||||
~QgsLegendLayer();
|
||||
|
||||
bool isLeafNode();
|
||||
QgsLegendItem::DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
|
||||
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() const;
|
||||
/**Returns first map layer's file or 0 if there's no QgsLegendLayerFile */
|
||||
QgsLegendLayerFile* firstLayerFile() const;
|
||||
/**Returns the map layers associated with the QgsLegendLayerFiles*/
|
||||
std::list<QgsMapLayer*> mapLayers();
|
||||
/**Returns the legend layer file items associated with this legend layer*/
|
||||
std::list<QgsLegendLayerFile*> legendLayerFiles();
|
||||
/**Returns the map layer associated the item*/
|
||||
QgsMapLayer* layer();
|
||||
QgsMapCanvasLayer& canvasLayer();
|
||||
/**Goes through all the legendlayerfiles and sets check state to checked/partially checked/unchecked*/
|
||||
void updateCheckState();
|
||||
//void updateCheckState();
|
||||
|
||||
/**Updates symbology of the layer and copies symbology to other layer files in the group*/
|
||||
void refreshSymbology( const QString& key, double widthScale = 1.0 );
|
||||
@ -71,9 +63,19 @@ class QgsLegendLayer : public QgsLegendItem
|
||||
/** called to add appropriate menu items to legend's popup menu */
|
||||
void addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction );
|
||||
|
||||
/** Set layer to be visible in canvas */
|
||||
void setVisible( bool visible = TRUE );
|
||||
/** Find out whether the layer is visible */
|
||||
bool isVisible();
|
||||
|
||||
void setInOverview( bool isInOverview = TRUE );
|
||||
/**Determines whether there are layers in overview*/
|
||||
bool isInOverview();
|
||||
|
||||
/**Returns a label for a layer. Is static such that
|
||||
the name can be passed to the constructor of QgsLegendLayer*/
|
||||
static QString nameFromLayer( QgsMapLayer* layer );
|
||||
|
||||
public slots:
|
||||
|
||||
/**Toggle show in overview*/
|
||||
@ -85,10 +87,12 @@ class QgsLegendLayer : public QgsLegendItem
|
||||
void saveAsShapefile();
|
||||
void saveSelectionAsShapefile();
|
||||
|
||||
/**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*/
|
||||
/**update the layer's icon to show whether is in editing mode or in overview */
|
||||
void updateIcon();
|
||||
|
||||
/**Layer name has changed - set it also in legend*/
|
||||
void layerNameChanged();
|
||||
|
||||
protected:
|
||||
|
||||
/** Prepare and change symbology for vector layer */
|
||||
@ -97,19 +101,13 @@ class QgsLegendLayer : public QgsLegendItem
|
||||
/** Prepare and change symbology for raster layer */
|
||||
void rasterLayerSymbology( QgsRasterLayer* mapLayer );
|
||||
|
||||
/** Removes the symbology items of a layer and adds new ones.
|
||||
* If other files are in the same legend layer, the new symbology settings are copied.
|
||||
* Note: the QIcon* are deleted and therefore need to be allocated by calling
|
||||
* functions using operator new
|
||||
*/
|
||||
/** Removes the symbology items of a layer and adds new ones. */
|
||||
void changeSymbologySettings( const QgsMapLayer* mapLayer, const SymbologyList& newSymbologyItems );
|
||||
|
||||
/** Copies the symbology settings of the layer to all maplayers in the QgsLegendLayerFileGroup.
|
||||
* This method should be called whenever a layer in this group changes it symbology settings
|
||||
*/
|
||||
void updateLayerSymbologySettings( const QgsMapLayer* mapLayer );
|
||||
QPixmap getOriginalPixmap();
|
||||
|
||||
QPixmap getOriginalPixmap() const;
|
||||
/**Save as shapefile (called from saveAsShapefile and saveSelectionAsShapefile)*/
|
||||
void saveAsShapefileGeneral( bool saveOnlySelection );
|
||||
|
||||
private:
|
||||
/** Helper method to make the font bold from all ctors.
|
||||
@ -117,6 +115,11 @@ class QgsLegendLayer : public QgsLegendItem
|
||||
* from the QTreeWidgetItem base class.
|
||||
*/
|
||||
void setupFont();
|
||||
|
||||
protected:
|
||||
|
||||
/** layer identified by its layer id */
|
||||
QgsMapCanvasLayer mLyr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,424 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tim Sutton *
|
||||
* aps02ts@macbuntu *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsapplication.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgslegend.h"
|
||||
#include "qgslegendlayer.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include "qgsmaprenderer.h"
|
||||
#include "qgsrasterlayer.h"
|
||||
#include "qgsvectorfilewriter.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsgenericprojectionselector.h"
|
||||
|
||||
// attribute table
|
||||
#include "qgsattributetabledialog.h"
|
||||
|
||||
|
||||
#include "qgsencodingfiledialog.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
|
||||
QgsLegendLayerFile::QgsLegendLayerFile( QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer )
|
||||
: QgsLegendItem( theLegendItem, theString ), mLyr( theLayer )
|
||||
{
|
||||
// Set the initial visibility flag for layers
|
||||
// This user option allows the user to turn off initial drawing of
|
||||
// layers when they are added to the map. This is useful when adding
|
||||
// many layers and the user wants to adjusty symbology, etc prior to
|
||||
// actually viewing the layer.
|
||||
QSettings settings;
|
||||
bool visible = settings.value( "/qgis/new_layers_visible", true ).toBool();
|
||||
mLyr.setVisible( visible );
|
||||
|
||||
// not in overview by default
|
||||
mLyr.setInOverview( FALSE );
|
||||
|
||||
mType = LEGEND_LAYER_FILE;
|
||||
|
||||
setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
setCheckState( 0, Qt::Checked );
|
||||
setText( 0, theString );
|
||||
|
||||
// Add check if vector layer when connecting to selectionChanged slot
|
||||
// Ticket #811 - racicot
|
||||
QgsMapLayer *currentLayer = mLyr.layer();
|
||||
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
|
||||
if ( isVectLyr )
|
||||
{
|
||||
connect( mLyr.layer(), SIGNAL( editingStarted() ), this, SLOT( updateLegendItem() ) );
|
||||
connect( mLyr.layer(), SIGNAL( editingStopped() ), this, SLOT( updateLegendItem() ) );
|
||||
}
|
||||
connect( mLyr.layer(), SIGNAL( layerNameChanged() ), this, SLOT( layerNameChanged() ) );
|
||||
}
|
||||
|
||||
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept( LEGEND_ITEM_TYPE type )
|
||||
{
|
||||
return NO_ACTION;
|
||||
}
|
||||
|
||||
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept( const QgsLegendItem* li ) const
|
||||
{
|
||||
if ( li->type() == QgsLegendItem::LEGEND_LAYER_FILE )
|
||||
{
|
||||
if ( li->parent() == this->parent() )
|
||||
{
|
||||
return REORDER;
|
||||
}
|
||||
}
|
||||
return NO_ACTION;
|
||||
}
|
||||
|
||||
QPixmap QgsLegendLayerFile::getOriginalPixmap() const
|
||||
{
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "mActionFileSmall.png" );
|
||||
return myPixmap;
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::updateLegendItem()
|
||||
{
|
||||
QPixmap pix = legend()->pixmaps().mOriginalPixmap;
|
||||
|
||||
if ( mLyr.isInOverview() )
|
||||
{
|
||||
//add overview glasses to the pixmap
|
||||
QPainter p( &pix );
|
||||
p.drawPixmap( 0, 0, legend()->pixmaps().mInOverviewPixmap );
|
||||
}
|
||||
if ( mLyr.layer()->isEditable() )
|
||||
{
|
||||
//add editing icon to the pixmap
|
||||
QPainter p( &pix );
|
||||
p.drawPixmap( 30, 0, legend()->pixmaps().mEditablePixmap );
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO:
|
||||
if(mLyr.layer()->hasProjectionError())
|
||||
{
|
||||
//add overview glasses to the pixmap
|
||||
QPainter p(&pix);
|
||||
p.drawPixmap(60,0, legend()->pixmaps().mProjectionErrorPixmap);
|
||||
}
|
||||
*/
|
||||
|
||||
QIcon theIcon( pix );
|
||||
setIcon( 0, theIcon );
|
||||
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::setIconAppearance( bool isInOverview,
|
||||
bool editable )
|
||||
{
|
||||
QPixmap newIcon( getOriginalPixmap() );
|
||||
|
||||
if ( isInOverview )
|
||||
{
|
||||
// Overlay the overview icon on the default icon
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "mIconOverview.png" );
|
||||
QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();
|
||||
}
|
||||
|
||||
if ( editable )
|
||||
{
|
||||
// Overlay the editable icon on the default icon
|
||||
QPixmap myPixmap = QgisApp::getThemePixmap( "mIconEditable.png" );
|
||||
QPainter p( &newIcon );
|
||||
p.drawPixmap( 0, 0, myPixmap );
|
||||
p.end();
|
||||
}
|
||||
|
||||
QIcon theIcon( newIcon );
|
||||
setIcon( 0, theIcon );
|
||||
|
||||
//also update the icon of the legend layer
|
||||
(( QgsLegendLayer* )( parent()->parent() ) )->updateIcon();
|
||||
}
|
||||
|
||||
|
||||
QString QgsLegendLayerFile::nameFromLayer( QgsMapLayer* layer )
|
||||
{
|
||||
QString sourcename = layer->publicSource(); //todo: move this duplicated code into a new function
|
||||
if ( sourcename.startsWith( "host", Qt::CaseInsensitive ) )
|
||||
{
|
||||
//this layer is a database layer
|
||||
//modify source string such that password is not visible
|
||||
sourcename = layer->name();
|
||||
}
|
||||
else
|
||||
{
|
||||
//modify source name such that only the file is visible
|
||||
sourcename = layer->publicSource().section( '/', -1, -1 );
|
||||
}
|
||||
return sourcename;
|
||||
}
|
||||
|
||||
|
||||
void QgsLegendLayerFile::setVisible( bool visible )
|
||||
{
|
||||
mLyr.setVisible( visible );
|
||||
}
|
||||
|
||||
bool QgsLegendLayerFile::isVisible()
|
||||
{
|
||||
return mLyr.isVisible();
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::setInOverview( bool isInOverview )
|
||||
{
|
||||
mLyr.setInOverview( isInOverview );
|
||||
}
|
||||
|
||||
bool QgsLegendLayerFile::isInOverview()
|
||||
{
|
||||
return mLyr.isInOverview();
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::showInOverview()
|
||||
{
|
||||
// toggle current status
|
||||
setInOverview( ! isInOverview() );
|
||||
|
||||
legend()->updateMapCanvasLayerSet();
|
||||
legend()->updateOverview();
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::saveAsShapefile()
|
||||
{
|
||||
saveAsShapefileGeneral( FALSE );
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::table()
|
||||
{
|
||||
QgsVectorLayer * myLayer = qobject_cast<QgsVectorLayer *>( mLyr.layer() );
|
||||
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer );
|
||||
mDialog->show();
|
||||
// the dialog will be deleted by itself on close
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::saveSelectionAsShapefile()
|
||||
{
|
||||
saveAsShapefileGeneral( TRUE );
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::saveAsShapefileGeneral( bool saveOnlySelection )
|
||||
{
|
||||
QgsCoordinateReferenceSystem destCRS;
|
||||
|
||||
if ( mLyr.layer()->type() != QgsMapLayer::VectorLayer )
|
||||
return;
|
||||
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mLyr.layer() );
|
||||
|
||||
// get a name for the shapefile
|
||||
// Get a file to process, starting at the current directory
|
||||
QSettings settings;
|
||||
QString filter = QString( "Shapefiles (*.shp)" );
|
||||
QString dirName = settings.value( "/UI/lastShapefileDir", "." ).toString();
|
||||
|
||||
QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog( 0,
|
||||
tr( "Save layer as..." ),
|
||||
dirName,
|
||||
filter,
|
||||
QString( "" ) );
|
||||
openFileDialog->setAcceptMode( QFileDialog::AcceptSave );
|
||||
|
||||
// allow for selection of more than one file
|
||||
//openFileDialog->setMode(QFileDialog::AnyFile);
|
||||
|
||||
if ( openFileDialog->exec() != QDialog::Accepted )
|
||||
return;
|
||||
|
||||
|
||||
QString encoding = openFileDialog->encoding();
|
||||
QString shapefileName = openFileDialog->selectedFiles().first();
|
||||
settings.setValue( "/UI/lastShapefileDir", QFileInfo( shapefileName ).absolutePath() );
|
||||
|
||||
|
||||
if ( shapefileName.isNull() )
|
||||
return;
|
||||
|
||||
// add the extension if not present
|
||||
if ( shapefileName.indexOf( ".shp" ) == -1 )
|
||||
{
|
||||
shapefileName += ".shp";
|
||||
}
|
||||
|
||||
destCRS = vlayer->srs();
|
||||
// Find out if we have projections enabled or not
|
||||
if ( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() )
|
||||
{
|
||||
destCRS = QgisApp::instance()->mapCanvas()->mapRenderer()->destinationSrs();
|
||||
}
|
||||
|
||||
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
|
||||
mySelector->setSelectedCrsId( destCRS.srsid() );
|
||||
mySelector->setMessage( tr( "Select the coordinate reference system for the saved shapefile. "
|
||||
"The data points will be transformed from the layer coordinate reference system." ) );
|
||||
|
||||
if ( mySelector->exec() )
|
||||
{
|
||||
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
destCRS = srs;
|
||||
// destCRS->createFromId(mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Aborted CS selection, don't save.
|
||||
delete mySelector;
|
||||
return;
|
||||
}
|
||||
|
||||
delete mySelector;
|
||||
|
||||
// overwrite the file - user will already have been prompted
|
||||
// to verify they want to overwrite by the file dialog above
|
||||
if ( QFile::exists( shapefileName ) )
|
||||
{
|
||||
if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ok if the file existed it should be deleted now so we can continue...
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
QgsVectorFileWriter::WriterError error;
|
||||
error = QgsVectorFileWriter::writeAsShapefile( vlayer, shapefileName, encoding, &destCRS, saveOnlySelection );
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
switch ( error )
|
||||
{
|
||||
case QgsVectorFileWriter::NoError:
|
||||
QMessageBox::information( 0, tr( "Saving done" ), tr( "Export to Shapefile has been completed" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrDriverNotFound:
|
||||
QMessageBox::warning( 0, tr( "Driver not found" ), tr( "ESRI Shapefile driver is not available" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrCreateDataSource:
|
||||
QMessageBox::warning( 0, tr( "Error creating shapefile" ),
|
||||
tr( "The shapefile could not be created (%1)" ).arg( shapefileName ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrCreateLayer:
|
||||
QMessageBox::warning( 0, tr( "Error" ), tr( "Layer creation failed" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrAttributeTypeUnsupported:
|
||||
QMessageBox::warning( 0, tr( "Error" ),
|
||||
tr( "Layer attribute table contains unsupported datatype(s)" ) );
|
||||
break;
|
||||
|
||||
case QgsVectorFileWriter::ErrAttributeCreationFailed:
|
||||
QMessageBox::warning( 0, tr( "Error" ),
|
||||
tr( "Creation of an attribute failed" ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool QgsLegendLayerFile::isEditing()
|
||||
{
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mLyr.layer() );
|
||||
return vlayer && vlayer->isEditable();
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::layerNameChanged()
|
||||
{
|
||||
QString name = mLyr.layer()->name();
|
||||
setText( 0, name );
|
||||
|
||||
// set also parent's name
|
||||
legend()->setName( this, name );
|
||||
}
|
||||
|
||||
void QgsLegendLayerFile::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction )
|
||||
{
|
||||
QgsMapLayer* lyr = layer();
|
||||
|
||||
// zoom to layer extent
|
||||
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
|
||||
tr( "&Zoom to layer extent" ), legend(), SLOT( legendLayerZoom() ) );
|
||||
|
||||
// show in overview
|
||||
QAction* showInOverviewAction = theMenu.addAction( tr( "&Show in overview" ), this, SLOT( showInOverview() ) );
|
||||
showInOverviewAction->setCheckable( true );
|
||||
showInOverviewAction->blockSignals( true );
|
||||
showInOverviewAction->setChecked( mLyr.isInOverview() );
|
||||
showInOverviewAction->blockSignals( false );
|
||||
|
||||
// remove from canvas
|
||||
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemove.png" ),
|
||||
tr( "&Remove" ), legend(), SLOT( legendLayerRemove() ) );
|
||||
|
||||
theMenu.addSeparator();
|
||||
|
||||
if ( lyr->type() == QgsMapLayer::VectorLayer )
|
||||
{
|
||||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
|
||||
|
||||
// attribute table
|
||||
theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
|
||||
|
||||
// editing
|
||||
int cap = vlayer->dataProvider()->capabilities();
|
||||
if ( cap & QgsVectorDataProvider::EditingCapabilities )
|
||||
{
|
||||
if ( toggleEditingAction )
|
||||
{
|
||||
theMenu.addAction( toggleEditingAction );
|
||||
}
|
||||
}
|
||||
|
||||
// save as shapefile
|
||||
theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
|
||||
|
||||
QAction* saveSelectionAction = theMenu.addAction( tr( "Save selection as shapefile..." ), this, SLOT( saveSelectionAsShapefile() ) );
|
||||
if ( vlayer->selectedFeatureCount() == 0 )
|
||||
{
|
||||
saveSelectionAction->setEnabled( false );
|
||||
}
|
||||
|
||||
theMenu.addSeparator();
|
||||
}
|
||||
else if ( lyr->type() == QgsMapLayer::RasterLayer )
|
||||
{
|
||||
// TODO: what was this for?
|
||||
//QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>(lyr);
|
||||
//theMenu.addAction(tr("&Convert to..."), rlayer, SLOT(convertTo()));
|
||||
}
|
||||
|
||||
// properties goes on bottom of menu for consistency with normal ui standards
|
||||
// e.g. kde stuff
|
||||
theMenu.addAction( tr( "&Properties" ), legend(), SLOT( legendLayerShowProperties() ) );
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2005 by Tim Sutton *
|
||||
* aps02ts@macbuntu *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef QGSLEGENDLAYERFILE_H
|
||||
#define QGSLEGENDLAYERFILE_H
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
#include "qgslegenditem.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
class QgsMapLayer;
|
||||
|
||||
/**
|
||||
@author Tim Sutton
|
||||
*/
|
||||
class QgsLegendLayerFile : public QgsLegendItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsLegendLayerFile( QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer );
|
||||
|
||||
bool isLeafNode() {return true;}
|
||||
DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
|
||||
QgsLegendItem::DRAG_ACTION accept( const QgsLegendItem* li ) const;
|
||||
QgsMapLayer* layer() { return mLyr.layer(); }
|
||||
const QgsMapLayer* layer() const { return mLyr.layer(); }
|
||||
QgsMapCanvasLayer& canvasLayer() { return mLyr; }
|
||||
|
||||
QPixmap getOriginalPixmap() const;
|
||||
|
||||
void setIconAppearance( bool isInOverview, bool editable );
|
||||
|
||||
/**Returns a label for a layer. Is static such that
|
||||
the name can be passed to the constructor of QgsLegendLayerFile*/
|
||||
static QString nameFromLayer( QgsMapLayer* layer );
|
||||
|
||||
void setVisible( bool visible = TRUE );
|
||||
bool isVisible();
|
||||
|
||||
void setInOverview( bool isInOverview = TRUE );
|
||||
bool isInOverview();
|
||||
|
||||
/** called to add appropriate menu items to legend's popup menu */
|
||||
void addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction );
|
||||
|
||||
public slots:
|
||||
/** updates item to the current state of the layer */
|
||||
void updateLegendItem();
|
||||
|
||||
/**Open attribute table*/
|
||||
void table();
|
||||
|
||||
/**Save as shapefile*/
|
||||
void saveAsShapefile();
|
||||
|
||||
/**Save selection as shapefile*/
|
||||
void saveSelectionAsShapefile();
|
||||
|
||||
/**Return editing status for layer*/
|
||||
bool isEditing();
|
||||
|
||||
/**Toggle show in overview*/
|
||||
void showInOverview();
|
||||
|
||||
/**Layer name has changed - set it also in legend*/
|
||||
void layerNameChanged();
|
||||
|
||||
protected:
|
||||
|
||||
/**Save as shapefile (called from saveAsShapefile and saveSelectionAsShapefile)*/
|
||||
void saveAsShapefileGeneral( bool saveOnlySelection );
|
||||
|
||||
/** layer identified by its layer id */
|
||||
QgsMapCanvasLayer mLyr;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,158 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgslegendlayerfilegroup.cpp - description
|
||||
-------------------
|
||||
begin : Juli 2005
|
||||
copyright : (C) 2005 by Marco Hugentobler
|
||||
email : marco.hugentobler@autoform.ch
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslegendlayer.h"
|
||||
#include "qgslegendlayerfilegroup.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgslegendsymbologygroup.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include "qgslogger.h"
|
||||
|
||||
QgsLegendLayerFileGroup::QgsLegendLayerFileGroup( QTreeWidgetItem* theItem, QString theString ): QgsLegendItem( theItem, theString )
|
||||
{
|
||||
mType = LEGEND_LAYER_FILE_GROUP;
|
||||
setText( 0, theString );
|
||||
}
|
||||
|
||||
QgsLegendItem::DRAG_ACTION QgsLegendLayerFileGroup::accept( LEGEND_ITEM_TYPE type )
|
||||
{
|
||||
if ( type == LEGEND_LAYER_FILE )
|
||||
{
|
||||
return INSERT; //there should be a way to already test, if the layers are symbology compatible
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO_ACTION;
|
||||
}
|
||||
}
|
||||
|
||||
QgsLegendItem::DRAG_ACTION QgsLegendLayerFileGroup::accept( const QgsLegendItem* li ) const
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
if ( li )
|
||||
{
|
||||
LEGEND_ITEM_TYPE type = li->type();
|
||||
if ( type == LEGEND_LAYER_FILE /*&& this != li->parent()*/ )
|
||||
{
|
||||
if ( child( 0 ) == 0 )
|
||||
{
|
||||
return INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsLegendLayerFile* llf = dynamic_cast<QgsLegendLayerFile *>( child( 0 ) );
|
||||
if ( llf )
|
||||
{
|
||||
QgsMapLayer* childlayer = llf->layer();
|
||||
const QgsMapLayer* newlayer = qobject_cast<const QgsLegendLayerFile *>( li )->layer();
|
||||
if ( newlayer->hasCompatibleSymbology( *childlayer ) )
|
||||
{
|
||||
return INSERT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO_ACTION;
|
||||
}
|
||||
|
||||
bool QgsLegendLayerFileGroup::insert( QgsLegendItem* newItem )
|
||||
{
|
||||
if ( newItem->type() == LEGEND_LAYER_FILE )
|
||||
{
|
||||
QgsLegendItem* oldItem = firstChild();
|
||||
|
||||
if ( !oldItem )//this item is the first child
|
||||
{
|
||||
insertChild( 0, newItem );
|
||||
return true;
|
||||
}
|
||||
//there are already legend layer files
|
||||
|
||||
//find the lowest sibling
|
||||
while ( oldItem->nextSibling() != 0 )
|
||||
{
|
||||
oldItem = oldItem->nextSibling();
|
||||
}
|
||||
QgsLegendLayerFile* thefile = qobject_cast<QgsLegendLayerFile *>( oldItem );
|
||||
|
||||
if ( !thefile )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QgsMapLayer* thelayer = thefile->layer();
|
||||
if ( !thelayer )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QgsMapLayer* newLayer = qobject_cast<QgsLegendLayerFile *>( newItem )->layer();
|
||||
if ( newLayer->hasCompatibleSymbology( *thelayer ) )
|
||||
{
|
||||
insertChild( childCount(), newItem );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool QgsLegendLayerFileGroup::containsLegendLayerFile( const QgsLegendLayerFile* llf ) const
|
||||
{
|
||||
bool result = false;
|
||||
for ( int i = 0; i < childCount(); ++i )
|
||||
{
|
||||
if ( llf == child( i ) )
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 )
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
if ( formerChild->type() == LEGEND_LAYER_FILE )
|
||||
{
|
||||
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( parent() );
|
||||
if ( ll )
|
||||
{
|
||||
ll->updateIcon();
|
||||
ll->updateCheckState();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgslegendlayerfilegroup.h - description
|
||||
-------------------
|
||||
begin : Juli 2005
|
||||
copyright : (C) 2005 by Marco Hugentobler
|
||||
email : marco.hugentobler@autoform.ch
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgslegenditem.h"
|
||||
|
||||
class QgsLegendLayerFile;
|
||||
|
||||
class QgsLegendLayerFileGroup: public QgsLegendItem
|
||||
{
|
||||
public:
|
||||
QgsLegendLayerFileGroup( QTreeWidgetItem* theItem, QString theString );
|
||||
bool isLeafNode() {return false;}
|
||||
DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
|
||||
QgsLegendItem::DRAG_ACTION accept( const QgsLegendItem* li ) const;
|
||||
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 );
|
||||
};
|
@ -19,8 +19,6 @@
|
||||
***************************************************************************/
|
||||
#include "qgsapplication.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgslegendlayerfilegroup.h"
|
||||
#include "qgslegendsymbologygroup.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include <QCoreApplication>
|
||||
|
@ -106,7 +106,6 @@
|
||||
#include "qgshelpviewer.h"
|
||||
#include "qgsgenericprojectionselector.h"
|
||||
#include "qgslegend.h"
|
||||
#include "qgslegendlayerfile.h"
|
||||
#include "qgslegendlayer.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
@ -4050,12 +4049,12 @@ void QgisApp::attributeTable()
|
||||
|
||||
void QgisApp::saveAsShapefile()
|
||||
{
|
||||
mMapLegend->currentLayerFile()->saveAsShapefile();
|
||||
mMapLegend->currentLegendLayer()->saveAsShapefile();
|
||||
}
|
||||
|
||||
void QgisApp::saveSelectionAsShapefile()
|
||||
{
|
||||
mMapLegend->currentLayerFile()->saveSelectionAsShapefile();
|
||||
mMapLegend->currentLegendLayer()->saveSelectionAsShapefile();
|
||||
}
|
||||
|
||||
void QgisApp::layerProperties()
|
||||
@ -4576,8 +4575,8 @@ void QgisApp::toggleEditing()
|
||||
if ( mMapCanvas && mMapCanvas->isDrawing() )
|
||||
return;
|
||||
|
||||
QgsLegendLayerFile* currentLayerFile = mMapLegend->currentLayerFile();
|
||||
if ( currentLayerFile )
|
||||
QgsLegendLayer* currentLayer = mMapLegend->currentLegendLayer();
|
||||
if ( currentLayer )
|
||||
{
|
||||
toggleEditing( mMapLegend->currentLayer() );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user