Skip to content

Commit 9dd9f36

Browse files
author
jef
committed
[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@13501 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f8b728b commit 9dd9f36

18 files changed

+442
-523
lines changed

images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,6 @@
374374
<file>themes/gis/plugins/spit.png</file>
375375
<file>themes/gis/plugins/wfs.png</file>
376376
<file>themes/gis/plugins/coordinate_capture/coordinate_capture.png</file>
377+
<file>themes/default/mActionSaveEdits.png</file>
377378
</qresource>
378379
</RCC>
821 Bytes
Loading

python/core/symbology-ng-core.sip

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ class QgsSymbolV2RenderContext
489489
//! @note added in 1.5
490490
void setRenderHints( int hints );
491491

492-
// Colour used for selections
493-
492+
// Color used for selections
494493
static QColor selectionColor();
495494

496495
double outputLineWidth(double width) const;

src/app/legend/qgslegend.cpp

Lines changed: 23 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232
#include "qgsmaprenderer.h"
3333
#include "qgsproject.h"
3434
#include "qgsrasterlayer.h"
35-
#include "qgsrasterlayerproperties.h"
36-
#include "qgsvectorlayerproperties.h"
37-
38-
#include "qgsattributetabledialog.h"
39-
40-
#include <cfloat>
35+
#include "qgsvectorlayer.h"
4136

4237
#include <QFont>
4338
#include <QDomDocument>
@@ -57,14 +52,15 @@ const int AUTOSCROLL_MARGIN = 16;
5752
5853
set mItemBeingMoved pointer to 0 to prevent SuSE 9.0 crash
5954
*/
60-
QgsLegend::QgsLegend( QWidget * parent, const char *name )
55+
QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
6156
: QTreeWidget( parent ),
6257
mMousePressedFlag( false ),
6358
mItemBeingMoved( 0 ),
64-
mToggleEditingAction( 0 ),
65-
mMapCanvas( 0 ),
59+
mMapCanvas( canvas ),
6660
mMinimumIconSize( 20, 20 )
6761
{
62+
setObjectName( name );
63+
6864
connect( this, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
6965
this, SLOT( handleItemChange( QTreeWidgetItem*, int ) ) );
7066

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

76+
// connect map layer registry signal to legend
77+
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ),
78+
this, SLOT( removeLayer( QString ) ) );
79+
connect( QgsMapLayerRegistry::instance(), SIGNAL( removedAll() ),
80+
this, SLOT( removeAll() ) );
81+
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ),
82+
this, SLOT( addLayer( QgsMapLayer * ) ) );
83+
84+
connect( mMapCanvas, SIGNAL( layersChanged() ),
85+
this, SLOT( refreshCheckStates() ) );
86+
8087
// Initialise the line indicator widget.
8188
mInsertionLine = new QWidget( viewport() );
8289
hideLine();
@@ -174,13 +181,8 @@ void QgsLegend::removeGroup( int groupIndex )
174181
}
175182
}
176183

177-
void QgsLegend::removeLayer( QString layer_key )
184+
void QgsLegend::removeLayer( QString layerId )
178185
{
179-
if ( !mMapCanvas || mMapCanvas->isDrawing() )
180-
{
181-
return;
182-
}
183-
184186
QgsDebugMsg( "called." );
185187

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

194-
if ( ll && ll->layer() && ll->layer()->getLayerID() == layer_key )
196+
if ( ll && ll->layer() && ll->layer()->getLayerID() == layerId )
195197
{
196198
removeItem( ll );
197199
delete ll;
198-
199200
break;
200201
}
201202

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

423424
void QgsLegend::mouseDoubleClickEvent( QMouseEvent* e )
424425
{
425-
if ( !mMapCanvas || mMapCanvas->isDrawing() )
426-
{
427-
return;
428-
}
429-
legendLayerShowProperties();
426+
QgisApp::instance()->layerProperties();
430427
}
431428

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

445442
if ( li->type() == QgsLegendItem::LEGEND_LAYER )
446443
{
447-
( static_cast<QgsLegendLayer*>( li ) )->addToPopupMenu( theMenu, mToggleEditingAction );
444+
qobject_cast<QgsLegendLayer*>( li )->addToPopupMenu( theMenu );
448445

449446
if ( li->parent() )
450447
{
@@ -565,17 +562,6 @@ void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )
565562
}
566563
}
567564

568-
void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
569-
{
570-
if ( mMapCanvas )
571-
{
572-
disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
573-
}
574-
575-
mMapCanvas = canvas;
576-
connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( refreshCheckStates() ) );
577-
}
578-
579565
QgsLegendLayer* QgsLegend::currentLegendLayer()
580566
{
581567
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
@@ -646,84 +632,16 @@ void QgsLegend::removeGroup( QgsLegendGroup * lg )
646632
QTreeWidgetItem * child = lg->child( 0 );
647633
while ( child )
648634
{
649-
setCurrentItem( child );
650-
removeCurrentLayer();
635+
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( child );
636+
if ( ll )
637+
QgsMapLayerRegistry::instance()->removeMapLayer( ll->layer()->getLayerID() );
651638
child = lg->child( 0 );
652639
}
653640
delete lg;
654-
adjustIconSize();
655-
}
656-
657-
void QgsLegend::removeCurrentLayer()
658-
{
659-
if ( !mMapCanvas || mMapCanvas->isDrawing() )
660-
{
661-
return;
662-
}
663-
664-
//if the current item is a legend layer: remove all layers of the current legendLayer
665-
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( currentItem() );
666-
if ( !ll )
667-
return;
668-
669-
removeLayer( ll->layer(), true );
670641

671642
adjustIconSize();
672643
}
673644

674-
bool QgsLegend::removeLayer( QgsMapLayer* ml, bool askCancelOnEditable )
675-
{
676-
if ( !ml )
677-
{
678-
return false;
679-
}
680-
681-
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
682-
if ( vl )
683-
{
684-
//is layer editable and changed?
685-
if ( vl->isEditable() && vl->isModified() )
686-
{
687-
QMessageBox::StandardButton commit;
688-
if ( askCancelOnEditable )
689-
{
690-
commit = QMessageBox::information( this,
691-
tr( "Stop editing" ),
692-
tr( "Do you want to save the changes to layer %1?" ).arg( vl->name() ),
693-
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
694-
if ( commit == QMessageBox::Cancel )
695-
{
696-
return false;
697-
}
698-
}
699-
else
700-
{
701-
commit = QMessageBox::information( this,
702-
tr( "Stop editing" ),
703-
tr( "Do you want to save the changes to layer %1?" ).arg( vl->name() ),
704-
QMessageBox::Save | QMessageBox::Discard );
705-
}
706-
707-
if ( commit == QMessageBox::Save )
708-
{
709-
if ( !vl->commitChanges() )
710-
{
711-
return false;
712-
}
713-
}
714-
else if ( commit == QMessageBox::Discard )
715-
{
716-
if ( !vl->rollBack() )
717-
{
718-
return false;
719-
}
720-
}
721-
}
722-
}
723-
QgsMapLayerRegistry::instance()->removeMapLayer( ml->getLayerID() );
724-
return true;
725-
}
726-
727645
void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
728646
{
729647
if ( !ml )
@@ -740,35 +658,6 @@ void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
740658
insertItem( layer, group );
741659
}
742660

743-
void QgsLegend::legendLayerShowProperties()
744-
{
745-
if ( !mMapCanvas || mMapCanvas->isDrawing() )
746-
{
747-
return;
748-
}
749-
750-
QgsLegendItem* li = dynamic_cast<QgsLegendItem *>( currentItem() );
751-
752-
if ( !li )
753-
{
754-
return;
755-
}
756-
757-
if ( li->type() != QgsLegendItem::LEGEND_LAYER )
758-
return;
759-
760-
QgsLegendLayer* ll = qobject_cast<QgsLegendLayer *>( li );
761-
if ( !ll )
762-
return;
763-
764-
//QgsDebugMsg("Showing layer properties dialog");
765-
766-
QgisApp::instance()->showLayerProperties( ll->layer() );
767-
768-
ll->updateIcon();
769-
770-
}
771-
772661
void QgsLegend::legendLayerShowInOverview()
773662
{
774663
if ( !mMapCanvas || mMapCanvas->isDrawing() )
@@ -1732,35 +1621,6 @@ void QgsLegend::legendLayerZoomNative()
17321621
}
17331622
}
17341623

1735-
void QgsLegend::legendLayerAttributeTable()
1736-
{
1737-
if ( !mMapCanvas || mMapCanvas->isDrawing() )
1738-
{
1739-
return;
1740-
}
1741-
1742-
QgsVectorLayer *vlayer = 0;
1743-
1744-
// try whether it's a legend layer
1745-
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( currentItem() );
1746-
if ( !ll )
1747-
{
1748-
// nothing selected
1749-
QMessageBox::information( this,
1750-
tr( "No Layer Selected" ),
1751-
tr( "To open an attribute table, you must select a vector layer in the legend" ) );
1752-
return;
1753-
}
1754-
1755-
vlayer = qobject_cast<QgsVectorLayer *>( ll->layer() );
1756-
if ( vlayer )
1757-
{
1758-
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( vlayer );
1759-
mDialog->show();
1760-
// the dialog will be deleted by itself on close
1761-
}
1762-
}
1763-
17641624
void QgsLegend::readProject( const QDomDocument & doc )
17651625
{
17661626
QDomNodeList nodes = doc.elementsByTagName( "legend" );

src/app/legend/qgslegend.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class QgsLegend : public QTreeWidget
9696
* @param theParent An optional parent widget
9797
* @param theName An optional name for the widget
9898
*/
99-
QgsLegend( QWidget * parent = 0, const char *name = 0 );
99+
QgsLegend( QgsMapCanvas *canvas, QWidget * parent = 0, const char *name = 0 );
100100

101101
//! Destructor
102102
~QgsLegend();
@@ -181,9 +181,6 @@ class QgsLegend : public QTreeWidget
181181
/**Removes an entry from mPixmapHeightValues*/
182182
void removePixmapHeightValue( int height );
183183

184-
/**Sets the toggle editing action. Usually called from QgisApp*/
185-
void setToggleEditingAction( QAction* editingAction ) {mToggleEditingAction = editingAction;}
186-
187184
/**Returns structure with legend pixmaps*/
188185
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
189186

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

201198
void setLayerVisible( QgsMapLayer * layer, bool visible );
202199

203-
void setMapCanvas( QgsMapCanvas * canvas );
204-
205200
/**Updates symbology items for a layer*/
206201
void refreshLayerSymbology( QString key, bool expandItem = true );
207202

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

246-
/**Removes the current LegendLayer*/
247-
void removeCurrentLayer();
248-
249-
/**Removes a layer. If the layer is editable, a dialog is shown where user can select 'save', 'discard' and optionally 'cancel'. Cancel
250-
is useful if a single layer is removed whereas on closing of the whole project or application, the cancel option may not be possible
251-
@param ml the maplayer to remove
252-
@param askCancelOnEditable gibe cancel option in the dialog for editable (and changed) layers
253-
@param return false if canceled or in case of error, true else*/
254-
bool removeLayer( QgsMapLayer* ml, bool askCancelOnEditable );
255-
256241
/*!
257242
* Moves a layer to a group.
258243
* @param ml the maplayer to move
@@ -272,12 +257,6 @@ class QgsLegend : public QTreeWidget
272257
Only works on raster layers*/
273258
void legendLayerZoomNative();
274259

275-
/**Show attribute table*/
276-
void legendLayerAttributeTable();
277-
278-
/**Shows the property dialog of the first legend layer file in a legend layer*/
279-
void legendLayerShowProperties();
280-
281260
/**Updates check states when the map canvas layer set is changed */
282261
void refreshCheckStates();
283262
protected:
@@ -440,9 +419,6 @@ class QgsLegend : public QTreeWidget
440419
decide if the mapcanvas really has to be refreshed*/
441420
std::deque<QString> mLayersPriorToMove;
442421

443-
/**Action for the legendlayer right click menu*/
444-
QAction* mToggleEditingAction;
445-
446422
/*!
447423
* A function to determine how far down in the list an item is (starting with one for the first Item).
448424
*If the item is not in the legend, -1 is returned

0 commit comments

Comments
 (0)