Skip to content

Commit acd18b5

Browse files
author
jef
committedJan 23, 2010
allow opening properties dialog for layer from plugins (better version of r12814)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12828 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d480f81 commit acd18b5

11 files changed

+88
-58
lines changed
 

‎python/gui/qgisinterface.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,16 @@ class QgisInterface : QObject
100100
/** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */
101101
virtual void removeDockWidget ( QDockWidget * dockwidget )=0;
102102

103-
/** refresh legend of a layer */
103+
/** refresh legend of a layer
104+
\note deprecated - use QgsLegendInterface::refreshLayerSymbology()
105+
*/
104106
virtual void refreshLegend( QgsMapLayer * layer )=0;
105107

108+
/** open layer properties
109+
\note added in 1.5
110+
*/
111+
virtual void showLayerProperties( QgsMapLayer * layer )=0;
112+
106113
/** Add window to Window menu. The action title is the window title
107114
* and the action should raise, unminimize and activate the window. */
108115
virtual void addWindow( QAction *action ) = 0;

‎python/gui/qgslegendinterface.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class QgsLegendInterface : QObject
3434
//! Move a layer to a group
3535
virtual void moveLayer( QgsMapLayer * layer, int groupIndex ) =0;
3636

37-
//! show layer propeties
38-
//! @note added in 1.5
39-
virtual void legendLayerShowProperties() =0;
37+
//! refresh layer symbology
38+
//! \note added in 1.5
39+
virtual void refreshLayerSymbology( QgsMapLayer *layer ) =0;
4040
};
4141

‎src/app/legend/qgsapplegendinterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgsapplegendinterface.h"
1919

2020
#include "qgslegend.h"
21-
21+
#include "qgsmaplayer.h"
2222

2323
QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
2424
: mLegend( legend )
@@ -58,7 +58,7 @@ QStringList QgsAppLegendInterface::groups()
5858
return mLegend->groups();
5959
}
6060

61-
void QgsAppLegendInterface::legendLayerShowProperties()
61+
void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
6262
{
63-
mLegend->legendLayerShowProperties();
63+
mLegend->refreshLayerSymbology( ml->getLayerID() );
6464
}

‎src/app/legend/qgsapplegendinterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ class QgsAppLegendInterface : public QgsLegendInterface
5353
void removeGroup( int groupIndex );
5454

5555
//! Move a layer to a group
56-
void moveLayer( QgsMapLayer * ml, int groupIndex );
56+
void moveLayer( QgsMapLayer *ml, int groupIndex );
5757

5858
//! Update an index
5959
void updateIndex( QModelIndex oldIndex, QModelIndex newIndex );
6060

61-
//! Show layer properties
62-
void legendLayerShowProperties();
61+
//! refresh layer symbology
62+
void refreshLayerSymbology( QgsMapLayer *ml );
6363

6464
private:
6565

‎src/app/legend/qgslegend.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -717,49 +717,7 @@ void QgsLegend::legendLayerShowProperties()
717717

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

720-
QgsMapLayer* ml = ll->layer();
721-
722-
/*
723-
TODO: Consider reusing the property dialogs again.
724-
Sometimes around mid 2005, the property dialogs were saved for later reuse;
725-
this resulted in a time savings when reopening the dialog. The code below
726-
cannot be used as is, however, simply by saving the dialog pointer here.
727-
Either the map layer needs to be passed as an argument to sync or else
728-
a separate copy of the dialog pointer needs to be stored with each layer.
729-
*/
730-
731-
if ( ml->type() == QgsMapLayer::RasterLayer )
732-
{
733-
QgsRasterLayerProperties *rlp = NULL; // See note above about reusing this
734-
if ( rlp )
735-
{
736-
rlp->sync();
737-
}
738-
else
739-
{
740-
rlp = new QgsRasterLayerProperties( ml );
741-
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), this, SLOT( refreshLayerSymbology( QString, bool ) ) );
742-
}
743-
rlp->exec();
744-
delete rlp; // delete since dialog cannot be reused without updating code
745-
}
746-
else // VECTOR
747-
{
748-
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( ml );
749-
750-
QgsVectorLayerProperties *vlp = NULL; // See note above about reusing this
751-
if ( vlp )
752-
{
753-
vlp->reset();
754-
}
755-
else
756-
{
757-
vlp = new QgsVectorLayerProperties( vlayer );
758-
connect( vlp, SIGNAL( refreshLegend( QString, bool ) ), this, SLOT( refreshLayerSymbology( QString, bool ) ) );
759-
}
760-
vlp->exec();
761-
delete vlp; // delete since dialog cannot be reused without updating code
762-
}
720+
QgisApp::instance()->showLayerProperties( ll->layer() );
763721

764722
ll->updateIcon();
765723

‎src/app/qgisapp.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
#include "qgsproviderregistry.h"
129129
#include "qgsrasterlayer.h"
130130
#include "qgsrasterlayerproperties.h"
131+
#include "qgsvectorlayerproperties.h"
131132
#include "qgsrectangle.h"
132133
#include "qgsrenderer.h"
133134
#include "qgswmssourceselect.h"
@@ -6080,3 +6081,48 @@ void QgisApp::readProject( const QDomDocument &doc )
60806081
{
60816082
projectChanged( doc );
60826083
}
6084+
6085+
void QgisApp::showLayerProperties( QgsMapLayer *ml )
6086+
{
6087+
/*
6088+
TODO: Consider reusing the property dialogs again.
6089+
Sometimes around mid 2005, the property dialogs were saved for later reuse;
6090+
this resulted in a time savings when reopening the dialog. The code below
6091+
cannot be used as is, however, simply by saving the dialog pointer here.
6092+
Either the map layer needs to be passed as an argument to sync or else
6093+
a separate copy of the dialog pointer needs to be stored with each layer.
6094+
*/
6095+
6096+
if ( ml->type() == QgsMapLayer::RasterLayer )
6097+
{
6098+
QgsRasterLayerProperties *rlp = NULL; // See note above about reusing this
6099+
if ( rlp )
6100+
{
6101+
rlp->sync();
6102+
}
6103+
else
6104+
{
6105+
rlp = new QgsRasterLayerProperties( ml );
6106+
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
6107+
}
6108+
rlp->exec();
6109+
delete rlp; // delete since dialog cannot be reused without updating code
6110+
}
6111+
else // VECTOR
6112+
{
6113+
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( ml );
6114+
6115+
QgsVectorLayerProperties *vlp = NULL; // See note above about reusing this
6116+
if ( vlp )
6117+
{
6118+
vlp->reset();
6119+
}
6120+
else
6121+
{
6122+
vlp = new QgsVectorLayerProperties( vlayer );
6123+
connect( vlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
6124+
}
6125+
vlp->exec();
6126+
delete vlp; // delete since dialog cannot be reused without updating code
6127+
}
6128+
}

‎src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ class QgisApp : public QMainWindow
352352
//! run python
353353
void runPythonString( const QString &expr );
354354

355+
//! show layer properties
356+
void showLayerProperties( QgsMapLayer *ml );
357+
355358
public slots:
356359
//! Zoom to full extent
357360
void zoomFull();

‎src/app/qgisappinterface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ void QgisAppInterface::refreshLegend( QgsMapLayer *l )
198198
}
199199
}
200200

201+
void QgisAppInterface::showLayerProperties( QgsMapLayer *l )
202+
{
203+
if( l && qgis )
204+
{
205+
qgis->showLayerProperties( l );
206+
}
207+
}
208+
201209
void QgisAppInterface::addWindow( QAction *action ) { qgis->addWindow( action ); }
202210
void QgisAppInterface::removeWindow( QAction *action ) { qgis->removeWindow( action ); }
203211

‎src/app/qgisappinterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class QgisAppInterface : public QgisInterface
115115

116116
virtual void refreshLegend( QgsMapLayer *l );
117117

118+
virtual void showLayerProperties( QgsMapLayer *l );
119+
118120
/** Add window to Window menu. The action title is the window title
119121
* and the action should raise, unminimize and activate the window. */
120122
virtual void addWindow( QAction *action );

‎src/gui/qgisinterface.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class QWidget;
3131
#include <map>
3232

3333

34-
class QgisApp;
3534
class QgsComposerView;
3635
class QgsMapLayer;
3736
class QgsMapCanvas;
@@ -135,9 +134,16 @@ class GUI_EXPORT QgisInterface : public QObject
135134
/** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */
136135
virtual void removeDockWidget( QDockWidget * dockwidget ) = 0;
137136

138-
/** refresh the legend of a layer */
137+
/** refresh the legend of a layer
138+
\note deprecated - use QgsLegendInterface::refreshLayerSymbology
139+
*/
139140
virtual void refreshLegend( QgsMapLayer *l ) = 0;
140141

142+
/** open layer properties dialog
143+
\note added in 1.5
144+
*/
145+
virtual void showLayerProperties( QgsMapLayer *l ) = 0;
146+
141147
/** Add window to Window menu. The action title is the window title
142148
* and the action should raise, unminimize and activate the window. */
143149
virtual void addWindow( QAction *action ) = 0;

‎src/gui/qgslegendinterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class GUI_EXPORT QgsLegendInterface : public QObject
6060
//! Move a layer to a group
6161
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
6262

63-
//! Show layer properties dialog
64-
// @note added in 1.5
65-
virtual void legendLayerShowProperties() = 0;
63+
//! Refresh layer symbology
64+
// @noted added in 1.5
65+
virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
6666
};
6767

6868
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.