10 changes: 9 additions & 1 deletion images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<file>themes/default/mActionNewFolder.png</file>
<file>themes/default/mActionNewVectorLayer.png</file>
<file>themes/default/mActionNodeTool.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOpenTable.png</file>
<file>themes/default/mActionOptions.png</file>
<file>themes/default/mActionPan.png</file>
Expand Down Expand Up @@ -156,32 +156,40 @@
<file>themes/default/mActionZoomOut.png</file>
<file>themes/default/mActionZoomToLayer.png</file>
<file>themes/default/mActionZoomToSelected.png</file>
<file>themes/default/mIconConnect.png</file>
<file>themes/default/mIconDbSchema.png</file>
<file>themes/default/mIconDelete.png</file>
<file>themes/default/mIconEditable.png</file>
<file>themes/default/mIconFavourites.png</file>
<file>themes/default/mIconFirst.png</file>
<file>themes/default/mIconGeometryLayer.png</file>
<file>themes/default/mIconLast.png</file>
<file>themes/default/mIconLayer.png</file>
<file>themes/default/mIconLineLayer.png</file>
<file>themes/default/mIconLock.png</file>
<file>themes/default/mIconNew.png</file>
<file>themes/default/mIconMssql.png</file>
<file>themes/default/mIconNext.png</file>
<file>themes/default/mIconNoPyramid.png</file>
<file>themes/default/mIconPointLayer.png</file>
<file>themes/default/mIconPolygonLayer.png</file>
<file>themes/default/mIconPostgis.png</file>
<file>themes/default/mIconPrevious.png</file>
<file>themes/default/mIconProjectionDisabled.png</file>
<file>themes/default/mIconProjectionEnabled.png</file>
<file>themes/default/mIconProjectionProblem.png</file>
<file>themes/default/mIconProperties.png</file>
<file>themes/default/mIconPyramid.png</file>
<file>themes/default/mIconSpatialite.png</file>
<file>themes/default/mIconStopRendering.png</file>
<file>themes/default/mIconRaster.png</file>
<file>themes/default/mIconRenderingEnabled.png</file>
<file>themes/default/mIconRenderingDisabled.png</file>
<file>themes/default/mIconSymbology.png</file>
<file>themes/default/mIconTableLayer.png</file>
<file>themes/default/mIconUnknownLayerType.png</file>
<file>themes/default/mIconWaitingForLayerType.png</file>
<file>themes/default/mIconWfs.png</file>
<file>themes/default/mIconWms.png</file>
<file>themes/default/mIconWmsLayer.png</file>
<file>themes/default/mIconWarn.png</file>
Expand Down
Binary file added images/themes/default/mIconConnect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconDbSchema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconFavourites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconMssql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconPostgis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconRaster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconSpatialite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconWfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
: mLegend( legend )
{
connect( legend, SIGNAL( itemAdded( QModelIndex ) ), this, SIGNAL( itemAdded( QModelIndex ) ) );
connect( legend, SIGNAL( itemMoved( QModelIndex, QModelIndex ) ), this, SLOT( updateIndex( QModelIndex, QModelIndex ) ) );
connect( legend, SIGNAL( itemMoved( QModelIndex, QModelIndex ) ), this, SIGNAL( groupRelationsChanged( ) ) );
connect( legend, SIGNAL( itemMovedGroup( QgsLegendItem *, int ) ), this, SIGNAL( groupRelationsChanged() ) );
// connect( legend, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SIGNAL( groupRelationsChanged() ) );
connect( legend, SIGNAL( itemRemoved() ), this, SIGNAL( itemRemoved() ) );
}

QgsAppLegendInterface::~QgsAppLegendInterface()
Expand Down
79 changes: 72 additions & 7 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@

const int AUTOSCROLL_MARGIN = 16;

// This function finds a unique group name [prefix1, prefix2, ...] by adding an
// incremental integer to prefix. It is necessary because group names are the
// only way of identifying groups in QgsLegendInterface.
// Could add a "parent" argument and use that instead, or pass it as prefix
static QString getUniqueGroupName( QString prefix, QStringList groups )
{
QString suffix;
if ( groups.size() == 0 )
{
suffix = "1";
}
else
{
// get a list of strings that match prefix, and keep the suffix
QStringList match = groups.filter( QRegExp( QString( "^" + prefix ) ) );
match.replaceInStrings( prefix, QString( "" ) );
// find the maximum
int max = 0;
foreach( QString m, match )
{
if ( m.toInt() > max )
max = m.toInt();
}
suffix = QString( "%1" ).arg( max + 1 );
}
return prefix + suffix;
}

QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
: QTreeWidget( parent )
, mMousePressedFlag( false )
Expand Down Expand Up @@ -162,19 +190,22 @@ int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
blockSignals( true );

bool nameEmpty = name.isEmpty();
if ( nameEmpty )
name = tr( "group" ); // some default name if none specified

QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );
QgsLegendGroup *group;

if ( parentGroup )
{
if ( nameEmpty )
name = getUniqueGroupName( tr( "sub-group" ), groups() );
group = new QgsLegendGroup( parentGroup, name );
}
else
{
if ( nameEmpty )
name = getUniqueGroupName( tr( "group" ), groups() );
group = new QgsLegendGroup( this, name );

if ( currentItem() )
{
moveItem( group, currentItem() );
Expand All @@ -188,6 +219,9 @@ int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
openEditor();

blockSignals( false );

emit itemAdded( groupIndex );

return groupIndex.row();
}

Expand Down Expand Up @@ -274,6 +308,7 @@ void QgsLegend::removeLayer( QString layerId )
updateMapCanvasLayerSet();
adjustIconSize();

emit itemRemoved();
if ( invLayerRemoved )
emit invisibleLayerRemoved();
}
Expand Down Expand Up @@ -617,8 +652,8 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
tr( "Zoom to Group" ), this, SLOT( legendLayerZoom() ) );

theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ),
tr( "&Remove" ), this, SLOT( legendGroupRemove() ) );
// use QGisApp::removeLayer() to remove all selected layers+groups
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );

theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ),
tr( "&Set Group CRS" ), this, SLOT( legendGroupSetCRS() ) );
Expand All @@ -628,6 +663,7 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
{
theMenu.addAction( tr( "Re&name" ), this, SLOT( openEditor() ) );
}

//
// Option to group layers, if the selection is more than one
//
Expand Down Expand Up @@ -868,6 +904,8 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
}
//make the QTreeWidget item up-to-date
doItemsLayout();

emit itemAdded( indexFromItem( llayer ) );
}

void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )
Expand Down Expand Up @@ -1099,6 +1137,8 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )

delete lg;

emit itemRemoved();

adjustIconSize();
}

Expand Down Expand Up @@ -1132,6 +1172,8 @@ void QgsLegend::moveLayer( QgsMapLayer *ml, int groupIndex )
return;

insertItem( layer, group );

emit itemMovedGroup( dynamic_cast<QgsLegendItem*>( layer ), groupIndex );
}

void QgsLegend::legendLayerShowInOverview()
Expand Down Expand Up @@ -1766,11 +1808,14 @@ void QgsLegend::insertItem( QTreeWidgetItem* move, QTreeWidgetItem* into )
}
intoItem->receive( movedItem );
movedItem->restoreAppearanceSettings();//apply the settings again
emit itemMovedGroup( movedItem, indexFromItem( intoItem ).row() );
}
}

void QgsLegend::moveItem( QTreeWidgetItem* move, QTreeWidgetItem* after )
{
QModelIndex oldIndex = indexFromItem( move );

QgsDebugMsgLevel( QString( "Moving layer : %1 (%2)" ).arg( move->text( 0 ) ).arg( move->type() ), 3 );
if ( after )
{
Expand Down Expand Up @@ -1809,6 +1854,8 @@ void QgsLegend::moveItem( QTreeWidgetItem* move, QTreeWidgetItem* after )
}

static_cast<QgsLegendItem*>( move )->restoreAppearanceSettings();//apply the settings again

emit itemMoved( oldIndex, indexFromItem( move ) );
}

void QgsLegend::removeItem( QTreeWidgetItem* item )
Expand Down Expand Up @@ -2435,24 +2482,42 @@ void QgsLegend::groupSelectedLayers()

if ( parent )
{
group = new QgsLegendGroup( parent, tr( "sub-group" ) );
group = new QgsLegendGroup( parent,
getUniqueGroupName( tr( "sub-group" ), groups() ) );
}
else
{
group = new QgsLegendGroup( this, tr( "group" ) );
group = new QgsLegendGroup( this,
getUniqueGroupName( tr( "group" ), groups() ) );
}

// save old indexes so we can notify changes
QList< QModelIndex > oldIndexes;
QList< QTreeWidgetItem* > selected;

foreach( QTreeWidgetItem * item, selectedItems() )
{
QgsLegendLayer* layer = dynamic_cast<QgsLegendLayer *>( item );
if ( layer )
{
insertItem( item, group );
oldIndexes.append( indexFromItem( item ) );
selected.append( item );
}
}
foreach( QTreeWidgetItem * item, selected )
{
insertItem( item, group );
}

editItem( group, 0 );

blockSignals( false );

// notify that group was added and that items were moved
emit itemAdded( indexFromItem( group ) );
for ( int i = 0; i < selected.size(); i++ )
{
emit itemMoved( oldIndexes[i], indexFromItem( selected[i] ) );
}
}

3 changes: 3 additions & 0 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ class QgsLegend : public QTreeWidget
void updateGroupCheckStates( QTreeWidgetItem *item );

signals:
void itemAdded( QModelIndex index );
void itemMoved( QModelIndex oldIndex, QModelIndex newIndex );
void itemMovedGroup( QgsLegendItem *item, int newGroupIndex ); // should we add oldGroup?
void itemRemoved( ); // should we add an argument?

void zOrderChanged();
void invisibleLayerRemoved();
Expand Down
Loading