~ubuntu-branches/ubuntu/wily/qgis/wily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
                              qgswfsplugin.h
                              -------------------
  begin                : July 25, 2006
  copyright            : (C) 2006 by Marco Hugentobler
  email                : marco dot hugentobler at karto dot baug dot ethz dot ch
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "qgisinterface.h"
#include "qgsapplication.h"
#include "qgsproviderregistry.h"
#include "qgswfssourceselect.h"
#include "qgssinglesymbolrenderer.h"
#include "qgsvectorlayer.h"
#include "qgswfsplugin.h"

#include <QFile>
#include <QToolBar>



static const QString name_ = QObject::tr( "WFS plugin" );
static const QString description_ = QObject::tr( "Adds WFS layers to the QGIS canvas" );
static const QString version_ = QObject::tr( "Version 0.1" );

QgsWFSPlugin::QgsWFSPlugin( QgisInterface* iface )
    : QgisPlugin( name_, description_, version_, QgisPlugin::MAPLAYER ),
    mIface( iface ), mWfsDialogAction( 0 )
{

}

QgsWFSPlugin::~QgsWFSPlugin()
{
  delete mWfsDialogAction;
}

void QgsWFSPlugin::initGui()
{
  if ( mIface )
  {
    mWfsDialogAction = new QAction( QIcon(), tr( "&Add WFS layer" ), 0 );
    setCurrentTheme( "" );
    QObject::connect( mWfsDialogAction, SIGNAL( triggered() ), this, SLOT( showSourceDialog() ) );
    mIface->layerToolBar()->addAction( mWfsDialogAction );
    mIface->addPluginToMenu( tr( "&Add WFS layer" ), mWfsDialogAction );
    // this is called when the icon theme is changed
    connect( mIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
  }
}

void QgsWFSPlugin::unload()
{
  mIface->removeToolBarIcon( mWfsDialogAction );
  mIface->removePluginMenu( tr( "&Add WFS layer" ), mWfsDialogAction );
  delete mWfsDialogAction;
  mWfsDialogAction = 0;
}

void QgsWFSPlugin::showSourceDialog()
{
  QgsWFSSourceSelect serverDialog( 0, mIface );
  serverDialog.exec();
}

//! Set icons to the current theme
void QgsWFSPlugin::setCurrentTheme( QString theThemeName )
{
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/wfs.png";
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/wfs.png";
  QString myQrcPath = ":/wfs.png";
  if ( QFile::exists( myCurThemePath ) )
  {
    mWfsDialogAction->setIcon( QIcon( myCurThemePath ) );
  }
  else if ( QFile::exists( myDefThemePath ) )
  {
    mWfsDialogAction->setIcon( QIcon( myDefThemePath ) );
  }
  else if ( QFile::exists( myQrcPath ) )
  {
    mWfsDialogAction->setIcon( QIcon( myQrcPath ) );
  }
  else
  {
    mWfsDialogAction->setIcon( QIcon() );
  }
}

QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
{
  return new QgsWFSPlugin( theQgisInterfacePointer );
}

QGISEXTERN QString name()
{
  return name_;
}

QGISEXTERN QString description()
{
  return description_;
}

QGISEXTERN QString version()
{
  return version_;
}

QGISEXTERN int type()
{
  return QgisPlugin::UI;
}

QGISEXTERN void unload( QgisPlugin* theQgsWFSPluginPointer )
{
  delete theQgsWFSPluginPointer;
}