Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE]
- save edits button added (implements #2579)
- subset option to layer menu (implements #2660)
- show selected feature count in status bar (implements #2708)
- temporary workaround for #2714
- refactored redundant code from legend to qgisapp:
  attribute table, save as, layer removal, layer properties
- some more cleanups



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13501 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 16, 2010
1 parent 1e4dde8 commit 5fca89d
Show file tree
Hide file tree
Showing 18 changed files with 442 additions and 523 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -374,5 +374,6 @@
<file>themes/gis/plugins/spit.png</file>
<file>themes/gis/plugins/wfs.png</file>
<file>themes/gis/plugins/coordinate_capture/coordinate_capture.png</file>
<file>themes/default/mActionSaveEdits.png</file>
</qresource>
</RCC>
Binary file added images/themes/default/mActionSaveEdits.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions python/core/symbology-ng-core.sip
Expand Up @@ -489,8 +489,7 @@ class QgsSymbolV2RenderContext
//! @note added in 1.5
void setRenderHints( int hints );

// Colour used for selections

// Color used for selections
static QColor selectionColor();

double outputLineWidth(double width) const;
Expand Down
186 changes: 23 additions & 163 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -32,12 +32,7 @@
#include "qgsmaprenderer.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h"
#include "qgsvectorlayerproperties.h"

#include "qgsattributetabledialog.h"

#include <cfloat>
#include "qgsvectorlayer.h"

#include <QFont>
#include <QDomDocument>
Expand All @@ -57,14 +52,15 @@ const int AUTOSCROLL_MARGIN = 16;
set mItemBeingMoved pointer to 0 to prevent SuSE 9.0 crash
*/
QgsLegend::QgsLegend( QWidget * parent, const char *name )
QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
: QTreeWidget( parent ),
mMousePressedFlag( false ),
mItemBeingMoved( 0 ),
mToggleEditingAction( 0 ),
mMapCanvas( 0 ),
mMapCanvas( canvas ),
mMinimumIconSize( 20, 20 )
{
setObjectName( name );

connect( this, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
this, SLOT( handleItemChange( QTreeWidgetItem*, int ) ) );

Expand All @@ -77,6 +73,17 @@ QgsLegend::QgsLegend( QWidget * parent, const char *name )
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
this, SLOT( writeProject( QDomDocument & ) ) );

// connect map layer registry signal to legend
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ),
this, SLOT( removeLayer( QString ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( removedAll() ),
this, SLOT( removeAll() ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ),
this, SLOT( addLayer( QgsMapLayer * ) ) );

connect( mMapCanvas, SIGNAL( layersChanged() ),
this, SLOT( refreshCheckStates() ) );

// Initialise the line indicator widget.
mInsertionLine = new QWidget( viewport() );
hideLine();
Expand Down Expand Up @@ -174,13 +181,8 @@ void QgsLegend::removeGroup( int groupIndex )
}
}

void QgsLegend::removeLayer( QString layer_key )
void QgsLegend::removeLayer( QString layerId )
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
{
return;
}

QgsDebugMsg( "called." );

for ( QTreeWidgetItem* theItem = firstItem(); theItem; theItem = nextItem( theItem ) )
Expand All @@ -191,11 +193,10 @@ void QgsLegend::removeLayer( QString layer_key )
// save legend layer (parent of a legend layer file we're going to delete)
QgsLegendLayer* ll = qobject_cast<QgsLegendLayer *>( li );

if ( ll && ll->layer() && ll->layer()->getLayerID() == layer_key )
if ( ll && ll->layer() && ll->layer()->getLayerID() == layerId )
{
removeItem( ll );
delete ll;

break;
}

Expand Down Expand Up @@ -422,11 +423,7 @@ void QgsLegend::mouseReleaseEvent( QMouseEvent * e )

void QgsLegend::mouseDoubleClickEvent( QMouseEvent* e )
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
{
return;
}
legendLayerShowProperties();
QgisApp::instance()->layerProperties();
}

void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& position )
Expand All @@ -444,7 +441,7 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi

if ( li->type() == QgsLegendItem::LEGEND_LAYER )
{
( static_cast<QgsLegendLayer*>( li ) )->addToPopupMenu( theMenu, mToggleEditingAction );
qobject_cast<QgsLegendLayer*>( li )->addToPopupMenu( theMenu );

if ( li->parent() )
{
Expand Down Expand Up @@ -565,17 +562,6 @@ void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )
}
}

void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
{
if ( mMapCanvas )
{
disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
}

mMapCanvas = canvas;
connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( refreshCheckStates() ) );
}

QgsLegendLayer* QgsLegend::currentLegendLayer()
{
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
Expand Down Expand Up @@ -646,84 +632,16 @@ void QgsLegend::removeGroup( QgsLegendGroup * lg )
QTreeWidgetItem * child = lg->child( 0 );
while ( child )
{
setCurrentItem( child );
removeCurrentLayer();
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( child );
if ( ll )
QgsMapLayerRegistry::instance()->removeMapLayer( ll->layer()->getLayerID() );
child = lg->child( 0 );
}
delete lg;
adjustIconSize();
}

void QgsLegend::removeCurrentLayer()
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
{
return;
}

//if the current item is a legend layer: remove all layers of the current legendLayer
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( currentItem() );
if ( !ll )
return;

removeLayer( ll->layer(), true );

adjustIconSize();
}

bool QgsLegend::removeLayer( QgsMapLayer* ml, bool askCancelOnEditable )
{
if ( !ml )
{
return false;
}

QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
if ( vl )
{
//is layer editable and changed?
if ( vl->isEditable() && vl->isModified() )
{
QMessageBox::StandardButton commit;
if ( askCancelOnEditable )
{
commit = QMessageBox::information( this,
tr( "Stop editing" ),
tr( "Do you want to save the changes to layer %1?" ).arg( vl->name() ),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
if ( commit == QMessageBox::Cancel )
{
return false;
}
}
else
{
commit = QMessageBox::information( this,
tr( "Stop editing" ),
tr( "Do you want to save the changes to layer %1?" ).arg( vl->name() ),
QMessageBox::Save | QMessageBox::Discard );
}

if ( commit == QMessageBox::Save )
{
if ( !vl->commitChanges() )
{
return false;
}
}
else if ( commit == QMessageBox::Discard )
{
if ( !vl->rollBack() )
{
return false;
}
}
}
}
QgsMapLayerRegistry::instance()->removeMapLayer( ml->getLayerID() );
return true;
}

void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
{
if ( !ml )
Expand All @@ -740,35 +658,6 @@ void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
insertItem( layer, group );
}

void QgsLegend::legendLayerShowProperties()
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
{
return;
}

QgsLegendItem* li = dynamic_cast<QgsLegendItem *>( currentItem() );

if ( !li )
{
return;
}

if ( li->type() != QgsLegendItem::LEGEND_LAYER )
return;

QgsLegendLayer* ll = qobject_cast<QgsLegendLayer *>( li );
if ( !ll )
return;

//QgsDebugMsg("Showing layer properties dialog");

QgisApp::instance()->showLayerProperties( ll->layer() );

ll->updateIcon();

}

void QgsLegend::legendLayerShowInOverview()
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
Expand Down Expand Up @@ -1732,35 +1621,6 @@ void QgsLegend::legendLayerZoomNative()
}
}

void QgsLegend::legendLayerAttributeTable()
{
if ( !mMapCanvas || mMapCanvas->isDrawing() )
{
return;
}

QgsVectorLayer *vlayer = 0;

// try whether it's a legend layer
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( currentItem() );
if ( !ll )
{
// nothing selected
QMessageBox::information( this,
tr( "No Layer Selected" ),
tr( "To open an attribute table, you must select a vector layer in the legend" ) );
return;
}

vlayer = qobject_cast<QgsVectorLayer *>( ll->layer() );
if ( vlayer )
{
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( vlayer );
mDialog->show();
// the dialog will be deleted by itself on close
}
}

void QgsLegend::readProject( const QDomDocument & doc )
{
QDomNodeList nodes = doc.elementsByTagName( "legend" );
Expand Down
26 changes: 1 addition & 25 deletions src/app/legend/qgslegend.h
Expand Up @@ -96,7 +96,7 @@ class QgsLegend : public QTreeWidget
* @param theParent An optional parent widget
* @param theName An optional name for the widget
*/
QgsLegend( QWidget * parent = 0, const char *name = 0 );
QgsLegend( QgsMapCanvas *canvas, QWidget * parent = 0, const char *name = 0 );

//! Destructor
~QgsLegend();
Expand Down Expand Up @@ -181,9 +181,6 @@ class QgsLegend : public QTreeWidget
/**Removes an entry from mPixmapHeightValues*/
void removePixmapHeightValue( int height );

/**Sets the toggle editing action. Usually called from QgisApp*/
void setToggleEditingAction( QAction* editingAction ) {mToggleEditingAction = editingAction;}

/**Returns structure with legend pixmaps*/
QgsLegendPixmaps& pixmaps() { return mPixmaps; }

Expand All @@ -200,8 +197,6 @@ class QgsLegend : public QTreeWidget

void setLayerVisible( QgsMapLayer * layer, bool visible );

void setMapCanvas( QgsMapCanvas * canvas );

/**Updates symbology items for a layer*/
void refreshLayerSymbology( QString key, bool expandItem = true );

Expand Down Expand Up @@ -243,16 +238,6 @@ class QgsLegend : public QTreeWidget
/** called to write legend settings to project */
void writeProject( QDomDocument & );

/**Removes the current LegendLayer*/
void removeCurrentLayer();

/**Removes a layer. If the layer is editable, a dialog is shown where user can select 'save', 'discard' and optionally 'cancel'. Cancel
is useful if a single layer is removed whereas on closing of the whole project or application, the cancel option may not be possible
@param ml the maplayer to remove
@param askCancelOnEditable gibe cancel option in the dialog for editable (and changed) layers
@param return false if canceled or in case of error, true else*/
bool removeLayer( QgsMapLayer* ml, bool askCancelOnEditable );

/*!
* Moves a layer to a group.
* @param ml the maplayer to move
Expand All @@ -272,12 +257,6 @@ class QgsLegend : public QTreeWidget
Only works on raster layers*/
void legendLayerZoomNative();

/**Show attribute table*/
void legendLayerAttributeTable();

/**Shows the property dialog of the first legend layer file in a legend layer*/
void legendLayerShowProperties();

/**Updates check states when the map canvas layer set is changed */
void refreshCheckStates();
protected:
Expand Down Expand Up @@ -440,9 +419,6 @@ class QgsLegend : public QTreeWidget
decide if the mapcanvas really has to be refreshed*/
std::deque<QString> mLayersPriorToMove;

/**Action for the legendlayer right click menu*/
QAction* mToggleEditingAction;

/*!
* A function to determine how far down in the list an item is (starting with one for the first Item).
*If the item is not in the legend, -1 is returned
Expand Down

0 comments on commit 5fca89d

Please sign in to comment.