I found a way to do it. Here is the code i used
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import resources_rc
class SelectFeaturesPlugin:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
def initGui(self):
# Create action that will start plugin configuration
self.action5 = QAction(QIcon(":/plugins/selectfeatures/icon.png"), u"Add Record", self.iface.mainWindow())
# connect the action to the run method
QObject.connect(self.action5, SIGNAL("triggered()"), self.addRecord)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action5)
self.iface.addPluginToMenu(u"&Add Record", self.action5)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removeToolBarIcon(self.action5)
self.iface.removePluginMenu(u"&Add Record",self.action5)
# run method that performs all the real work
def addRecord(self):
feat = QgsFeature()
layer = self.iface.activeLayer()
layer.startEditing()
layer.addFeature( feat )
from myattrdialog import AttributeDialog
dlg = AttributeDialog( layer )
if not dlg.exec_():
return
#Populate the feature attrs map usin the values the user inserted in the dialog
feat.setAttributeMap( dlg.getFeatureAttributeMap() )
layer.commitChanges()