Skip to content

Commit

Permalink
[FEATURE] add QgisInterface::setActiveLayer()
Browse files Browse the repository at this point in the history
also fixes #2167


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12358 c8812cc2-4d05-0410-92ff-de0c093fc19c
jef committed Dec 7, 2009
1 parent 266e511 commit cf519de
Showing 9 changed files with 175 additions and 132 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
@@ -52,6 +52,10 @@ class QgisInterface : QObject
//! Get pointer to the active layer (layer selected in the legend)
virtual QgsMapLayer *activeLayer()=0;

//! Get pointer to the active layer (layer selected in the legend)
//! added in 1.4
virtual bool setActiveLayer( QgsMapLayer * )=0;

//! Add an icon to the plugins toolbar
virtual int addToolBarIcon(QAction *qAction) =0;
//! Remove an action (icon) from the plugin toolbar
266 changes: 140 additions & 126 deletions src/app/legend/qgslegend.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
@@ -103,6 +103,10 @@ class QgsLegend : public QTreeWidget
Else, 0 is returned.*/
QgsMapLayer* currentLayer();

/*!set the current layer
returns true if the layer exists, false otherwise*/
bool setCurrentLayer( QgsMapLayer *layer );

/**Writes the content of the legend to a project file*/
bool writeXML( QDomNode & layer_node, QDomDocument & document );

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

/**Returns the legend layer to which a map layer gelongs*/
/**Returns the legend layer to which a map layer belongs to*/
QgsLegendLayer* findLegendLayer( const QString& layerKey );

/**Returns the legend layer to which a map layer belongs to*/
QgsLegendLayer* findLegendLayer( const QgsMapLayer *layer );

/**Checks mPixmapWidthValues and mPixmapHeightValues and sets a new icon size if necessary*/
void adjustIconSize();

4 changes: 1 addition & 3 deletions src/app/legend/qgslegenditem.h
Original file line number Diff line number Diff line change
@@ -52,9 +52,7 @@ class QgsLegendItem : public QTreeWidgetItem, public QObject
LEGEND_SYMBOL_GROUP,
LEGEND_SYMBOL_ITEM,
LEGEND_VECTOR_SYMBOL_ITEM,
LEGEND_LAYER_FILE_GROUP,
LEGEND_LAYER_FILE
} ;
};

/**Describes the action that will be done if the mouse button will be released after a drag*/
enum DRAG_ACTION
8 changes: 7 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
@@ -4567,7 +4567,13 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
/** Get a pointer to the currently selected map layer */
QgsMapLayer *QgisApp::activeLayer()
{
return ( mMapLegend->currentLayer() );
return mMapLegend->currentLayer();
}

/** set the current layer */
bool QgisApp::setActiveLayer( QgsMapLayer *layer )
{
return mMapLegend->setCurrentLayer( layer );
}

/** Add a vector layer directly without prompting user for location
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
@@ -474,6 +474,8 @@ class QgisApp : public QMainWindow
*/
//! Return pointer to the active layer
QgsMapLayer *activeLayer();
//! set the active layer
bool setActiveLayer( QgsMapLayer * );
//! Open the help contents in a browser
void helpContents();
//! Open the QGIS homepage in users browser
6 changes: 5 additions & 1 deletion src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
***************************************************************************/
/* $Id$ */

#include <iostream>
#include <QFileInfo>
#include <QString>
#include <QMenu>
@@ -108,6 +107,11 @@ QgsMapLayer *QgisAppInterface::activeLayer()
return qgis->activeLayer();
}

bool QgisAppInterface::setActiveLayer( QgsMapLayer *layer )
{
return qgis->setActiveLayer( layer );
}

void QgisAppInterface::addPluginToMenu( QString name, QAction* action )
{
qgis->addPluginToMenu( name, action );
3 changes: 3 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
@@ -68,6 +68,9 @@ class QgisAppInterface : public QgisInterface
//! Get pointer to the active layer (layer selected in the legend)
QgsMapLayer *activeLayer();

//! set the active layer (layer selected in the legend)
bool setActiveLayer( QgsMapLayer *layer );

//! Add an icon to the plugins toolbar
int addToolBarIcon( QAction *qAction );
//! Remove an icon (action) from the plugin toolbar
5 changes: 5 additions & 0 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
@@ -95,6 +95,11 @@ class GUI_EXPORT QgisInterface : public QObject
//! Get pointer to the active layer (layer selected in the legend)
virtual QgsMapLayer *activeLayer() = 0;

//! Set the active layer (layer gets selected in the legend)
//! returns true if the layer exists, false otherwise
//! added in 1.4
virtual bool setActiveLayer( QgsMapLayer * ) = 0;

//! Add an icon to the plugins toolbar
virtual int addToolBarIcon( QAction *qAction ) = 0;

0 comments on commit cf519de

Please sign in to comment.