Skip to content

Commit

Permalink
allow opening properties dialog for layer from plugins (better versio…
Browse files Browse the repository at this point in the history
…n of r12814)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12828 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 23, 2010
1 parent d480f81 commit acd18b5
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 58 deletions.
9 changes: 8 additions & 1 deletion python/gui/qgisinterface.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ class QgisInterface : QObject
/** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */ /** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */
virtual void removeDockWidget ( QDockWidget * dockwidget )=0; virtual void removeDockWidget ( QDockWidget * dockwidget )=0;


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


/** open layer properties
\note added in 1.5
*/
virtual void showLayerProperties( QgsMapLayer * layer )=0;

/** Add window to Window menu. The action title is the window title /** Add window to Window menu. The action title is the window title
* and the action should raise, unminimize and activate the window. */ * and the action should raise, unminimize and activate the window. */
virtual void addWindow( QAction *action ) = 0; virtual void addWindow( QAction *action ) = 0;
Expand Down
6 changes: 3 additions & 3 deletions python/gui/qgslegendinterface.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class QgsLegendInterface : QObject
//! Move a layer to a group //! Move a layer to a group
virtual void moveLayer( QgsMapLayer * layer, int groupIndex ) =0; virtual void moveLayer( QgsMapLayer * layer, int groupIndex ) =0;


//! show layer propeties //! refresh layer symbology
//! @note added in 1.5 //! \note added in 1.5
virtual void legendLayerShowProperties() =0; virtual void refreshLayerSymbology( QgsMapLayer *layer ) =0;
}; };


6 changes: 3 additions & 3 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "qgsapplegendinterface.h" #include "qgsapplegendinterface.h"


#include "qgslegend.h" #include "qgslegend.h"

#include "qgsmaplayer.h"


QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend ) QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
: mLegend( legend ) : mLegend( legend )
Expand Down Expand Up @@ -58,7 +58,7 @@ QStringList QgsAppLegendInterface::groups()
return mLegend->groups(); return mLegend->groups();
} }


void QgsAppLegendInterface::legendLayerShowProperties() void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
{ {
mLegend->legendLayerShowProperties(); mLegend->refreshLayerSymbology( ml->getLayerID() );
} }
6 changes: 3 additions & 3 deletions src/app/legend/qgsapplegendinterface.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class QgsAppLegendInterface : public QgsLegendInterface
void removeGroup( int groupIndex ); void removeGroup( int groupIndex );


//! Move a layer to a group //! Move a layer to a group
void moveLayer( QgsMapLayer * ml, int groupIndex ); void moveLayer( QgsMapLayer *ml, int groupIndex );


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


//! Show layer properties //! refresh layer symbology
void legendLayerShowProperties(); void refreshLayerSymbology( QgsMapLayer *ml );


private: private:


Expand Down
44 changes: 1 addition & 43 deletions src/app/legend/qgslegend.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -717,49 +717,7 @@ void QgsLegend::legendLayerShowProperties()


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


QgsMapLayer* ml = ll->layer(); QgisApp::instance()->showLayerProperties( ll->layer() );

/*
TODO: Consider reusing the property dialogs again.
Sometimes around mid 2005, the property dialogs were saved for later reuse;
this resulted in a time savings when reopening the dialog. The code below
cannot be used as is, however, simply by saving the dialog pointer here.
Either the map layer needs to be passed as an argument to sync or else
a separate copy of the dialog pointer needs to be stored with each layer.
*/

if ( ml->type() == QgsMapLayer::RasterLayer )
{
QgsRasterLayerProperties *rlp = NULL; // See note above about reusing this
if ( rlp )
{
rlp->sync();
}
else
{
rlp = new QgsRasterLayerProperties( ml );
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), this, SLOT( refreshLayerSymbology( QString, bool ) ) );
}
rlp->exec();
delete rlp; // delete since dialog cannot be reused without updating code
}
else // VECTOR
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( ml );

QgsVectorLayerProperties *vlp = NULL; // See note above about reusing this
if ( vlp )
{
vlp->reset();
}
else
{
vlp = new QgsVectorLayerProperties( vlayer );
connect( vlp, SIGNAL( refreshLegend( QString, bool ) ), this, SLOT( refreshLayerSymbology( QString, bool ) ) );
}
vlp->exec();
delete vlp; // delete since dialog cannot be reused without updating code
}


ll->updateIcon(); ll->updateIcon();


Expand Down
46 changes: 46 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
#include "qgsproviderregistry.h" #include "qgsproviderregistry.h"
#include "qgsrasterlayer.h" #include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h" #include "qgsrasterlayerproperties.h"
#include "qgsvectorlayerproperties.h"
#include "qgsrectangle.h" #include "qgsrectangle.h"
#include "qgsrenderer.h" #include "qgsrenderer.h"
#include "qgswmssourceselect.h" #include "qgswmssourceselect.h"
Expand Down Expand Up @@ -6080,3 +6081,48 @@ void QgisApp::readProject( const QDomDocument &doc )
{ {
projectChanged( doc ); projectChanged( doc );
} }

void QgisApp::showLayerProperties( QgsMapLayer *ml )
{
/*
TODO: Consider reusing the property dialogs again.
Sometimes around mid 2005, the property dialogs were saved for later reuse;
this resulted in a time savings when reopening the dialog. The code below
cannot be used as is, however, simply by saving the dialog pointer here.
Either the map layer needs to be passed as an argument to sync or else
a separate copy of the dialog pointer needs to be stored with each layer.
*/

if ( ml->type() == QgsMapLayer::RasterLayer )
{
QgsRasterLayerProperties *rlp = NULL; // See note above about reusing this
if ( rlp )
{
rlp->sync();
}
else
{
rlp = new QgsRasterLayerProperties( ml );
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
}
rlp->exec();
delete rlp; // delete since dialog cannot be reused without updating code
}
else // VECTOR
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( ml );

QgsVectorLayerProperties *vlp = NULL; // See note above about reusing this
if ( vlp )
{
vlp->reset();
}
else
{
vlp = new QgsVectorLayerProperties( vlayer );
connect( vlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
}
vlp->exec();
delete vlp; // delete since dialog cannot be reused without updating code
}
}
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ class QgisApp : public QMainWindow
//! run python //! run python
void runPythonString( const QString &expr ); void runPythonString( const QString &expr );


//! show layer properties
void showLayerProperties( QgsMapLayer *ml );

public slots: public slots:
//! Zoom to full extent //! Zoom to full extent
void zoomFull(); void zoomFull();
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgisappinterface.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ void QgisAppInterface::refreshLegend( QgsMapLayer *l )
} }
} }


void QgisAppInterface::showLayerProperties( QgsMapLayer *l )
{
if( l && qgis )
{
qgis->showLayerProperties( l );
}
}

void QgisAppInterface::addWindow( QAction *action ) { qgis->addWindow( action ); } void QgisAppInterface::addWindow( QAction *action ) { qgis->addWindow( action ); }
void QgisAppInterface::removeWindow( QAction *action ) { qgis->removeWindow( action ); } void QgisAppInterface::removeWindow( QAction *action ) { qgis->removeWindow( action ); }


Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class QgisAppInterface : public QgisInterface


virtual void refreshLegend( QgsMapLayer *l ); virtual void refreshLegend( QgsMapLayer *l );


virtual void showLayerProperties( QgsMapLayer *l );

/** Add window to Window menu. The action title is the window title /** Add window to Window menu. The action title is the window title
* and the action should raise, unminimize and activate the window. */ * and the action should raise, unminimize and activate the window. */
virtual void addWindow( QAction *action ); virtual void addWindow( QAction *action );
Expand Down
10 changes: 8 additions & 2 deletions src/gui/qgisinterface.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class QWidget;
#include <map> #include <map>




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


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


/** open layer properties dialog
\note added in 1.5
*/
virtual void showLayerProperties( QgsMapLayer *l ) = 0;

/** Add window to Window menu. The action title is the window title /** Add window to Window menu. The action title is the window title
* and the action should raise, unminimize and activate the window. */ * and the action should raise, unminimize and activate the window. */
virtual void addWindow( QAction *action ) = 0; virtual void addWindow( QAction *action ) = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgslegendinterface.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class GUI_EXPORT QgsLegendInterface : public QObject
//! Move a layer to a group //! Move a layer to a group
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0; virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;


//! Show layer properties dialog //! Refresh layer symbology
// @note added in 1.5 // @noted added in 1.5
virtual void legendLayerShowProperties() = 0; virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
}; };


#endif #endif

0 comments on commit acd18b5

Please sign in to comment.