Plugin initialization

Create QGIS project

Use Layer ‣ Add layer ‣ Add vector layer, icon mActionAddOgrLayer Add vector layer or Ctrl+Shift+V. Add multiple layers to your new QGIS project.

../_images/qgis-project.png

Fig. 15 Sample QGIS project.

Activate plugin

In Plugins ‣ Manage and install plugins search and activate the Save Views plugin.

../_images/save-views-enable.png

Fig. 16 Activate the plugin.

See a new icon in the toolbar new_plugin1. Plugin can be open.

../_images/plugin-ui-template.png

Fig. 17 Empty plugin dialogue.

Qt Designer

Start the Qt Desginer tool and open the save_views_dockwidget_base.ui file.

../_images/qt_designer_01.png

Fig. 18 The dialogue is empty so far.

The code

The key file is save_views.py and the run() method:

 1    def run(self):
 2        """Run method that loads and starts the plugin"""
 3
 4        if not self.pluginIsActive:
 5            self.pluginIsActive = True
 6
 7            #print "** STARTING SaveViews"
 8
 9            # dockwidget may not exist if:
10            #    first run of plugin
11            #    removed on close (see self.onClosePlugin method)
12            if self.dockwidget == None:
13                # Create the dockwidget (after translation) and keep reference
14                self.dockwidget = SaveViewsDockWidget()
15
16            # connect to provide cleanup on closing of dockwidget
17            self.dockwidget.closingPlugin.connect(self.onClosePlugin)
18
19            # show the dockwidget
20            # TODO: fix to allow choice of dock location
21            self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
22            self.dockwidget.show()

Note

The code can be downloaded from our Github.