Skip to content

Commit 35e9935

Browse files
author
jef
committedDec 7, 2009
[FEATURE] add QgisInterface::setActiveLayer()
also fixes #2167 git-svn-id: http://svn.osgeo.org/qgis/trunk@12358 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 43183fa commit 35e9935

File tree

9 files changed

+175
-132
lines changed

9 files changed

+175
-132
lines changed
 

‎python/gui/qgisinterface.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class QgisInterface : QObject
5252
//! Get pointer to the active layer (layer selected in the legend)
5353
virtual QgsMapLayer *activeLayer()=0;
5454

55+
//! Get pointer to the active layer (layer selected in the legend)
56+
//! added in 1.4
57+
virtual bool setActiveLayer( QgsMapLayer * )=0;
58+
5559
//! Add an icon to the plugins toolbar
5660
virtual int addToolBarIcon(QAction *qAction) =0;
5761
//! Remove an action (icon) from the plugin toolbar

‎src/app/legend/qgslegend.cpp

Lines changed: 140 additions & 126 deletions
Large diffs are not rendered by default.

‎src/app/legend/qgslegend.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class QgsLegend : public QTreeWidget
103103
Else, 0 is returned.*/
104104
QgsMapLayer* currentLayer();
105105

106+
/*!set the current layer
107+
returns true if the layer exists, false otherwise*/
108+
bool setCurrentLayer( QgsMapLayer *layer );
109+
106110
/**Writes the content of the legend to a project file*/
107111
bool writeXML( QDomNode & layer_node, QDomDocument & document );
108112

@@ -285,9 +289,12 @@ class QgsLegend : public QTreeWidget
285289
/**Moves an item back to the position where storeInitialPosition has been called*/
286290
void resetToInitialPosition( QTreeWidgetItem* li );
287291

288-
/**Returns the legend layer to which a map layer gelongs*/
292+
/**Returns the legend layer to which a map layer belongs to*/
289293
QgsLegendLayer* findLegendLayer( const QString& layerKey );
290294

295+
/**Returns the legend layer to which a map layer belongs to*/
296+
QgsLegendLayer* findLegendLayer( const QgsMapLayer *layer );
297+
291298
/**Checks mPixmapWidthValues and mPixmapHeightValues and sets a new icon size if necessary*/
292299
void adjustIconSize();
293300

‎src/app/legend/qgslegenditem.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ class QgsLegendItem : public QTreeWidgetItem, public QObject
5252
LEGEND_SYMBOL_GROUP,
5353
LEGEND_SYMBOL_ITEM,
5454
LEGEND_VECTOR_SYMBOL_ITEM,
55-
LEGEND_LAYER_FILE_GROUP,
56-
LEGEND_LAYER_FILE
57-
} ;
55+
};
5856

5957
/**Describes the action that will be done if the mouse button will be released after a drag*/
6058
enum DRAG_ACTION

‎src/app/qgisapp.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4567,7 +4567,13 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
45674567
/** Get a pointer to the currently selected map layer */
45684568
QgsMapLayer *QgisApp::activeLayer()
45694569
{
4570-
return ( mMapLegend->currentLayer() );
4570+
return mMapLegend->currentLayer();
4571+
}
4572+
4573+
/** set the current layer */
4574+
bool QgisApp::setActiveLayer( QgsMapLayer *layer )
4575+
{
4576+
return mMapLegend->setCurrentLayer( layer );
45714577
}
45724578

45734579
/** Add a vector layer directly without prompting user for location

‎src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ class QgisApp : public QMainWindow
474474
*/
475475
//! Return pointer to the active layer
476476
QgsMapLayer *activeLayer();
477+
//! set the active layer
478+
bool setActiveLayer( QgsMapLayer * );
477479
//! Open the help contents in a browser
478480
void helpContents();
479481
//! Open the QGIS homepage in users browser

‎src/app/qgisappinterface.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
***************************************************************************/
1818
/* $Id$ */
1919

20-
#include <iostream>
2120
#include <QFileInfo>
2221
#include <QString>
2322
#include <QMenu>
@@ -108,6 +107,11 @@ QgsMapLayer *QgisAppInterface::activeLayer()
108107
return qgis->activeLayer();
109108
}
110109

110+
bool QgisAppInterface::setActiveLayer( QgsMapLayer *layer )
111+
{
112+
return qgis->setActiveLayer( layer );
113+
}
114+
111115
void QgisAppInterface::addPluginToMenu( QString name, QAction* action )
112116
{
113117
qgis->addPluginToMenu( name, action );

‎src/app/qgisappinterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class QgisAppInterface : public QgisInterface
6868
//! Get pointer to the active layer (layer selected in the legend)
6969
QgsMapLayer *activeLayer();
7070

71+
//! set the active layer (layer selected in the legend)
72+
bool setActiveLayer( QgsMapLayer *layer );
73+
7174
//! Add an icon to the plugins toolbar
7275
int addToolBarIcon( QAction *qAction );
7376
//! Remove an icon (action) from the plugin toolbar

‎src/gui/qgisinterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ class GUI_EXPORT QgisInterface : public QObject
9595
//! Get pointer to the active layer (layer selected in the legend)
9696
virtual QgsMapLayer *activeLayer() = 0;
9797

98+
//! Set the active layer (layer gets selected in the legend)
99+
//! returns true if the layer exists, false otherwise
100+
//! added in 1.4
101+
virtual bool setActiveLayer( QgsMapLayer * ) = 0;
102+
98103
//! Add an icon to the plugins toolbar
99104
virtual int addToolBarIcon( QAction *qAction ) = 0;
100105

0 commit comments

Comments
 (0)
Please sign in to comment.