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. 17 Sample QGIS project.

Activate plugin

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

../_images/save-views-enable1.png

Fig. 18 Activate the plugin.

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

../_images/plugin-ui-template1.png

Fig. 19 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. 20 The dialogue is empty so far.

The code

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    def run(self):
        """Run method that loads and starts the plugin"""

        if not self.pluginIsActive:
            self.pluginIsActive = True

            #print "** STARTING SaveViews"

            # dockwidget may not exist if:
            #    first run of plugin
            #    removed on close (see self.onClosePlugin method)
            if self.dockwidget == None:
                # Create the dockwidget (after translation) and keep reference
                self.dockwidget = SaveViewsDockWidget()

            # connect to provide cleanup on closing of dockwidget
            self.dockwidget.closingPlugin.connect(self.onClosePlugin)

            # show the dockwidget
            # TODO: fix to allow choice of dock location
            self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
            self.dockwidget.show()

Note

The code can be downloaded from our Github.