<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Verdana;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
@page Section1
        {size:21.0cm 842.0pt;
        margin:72.0pt 89.85pt 72.0pt 89.85pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>Hi All!<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>I&#8217;m trying to use custom forms for adding and editing
features within a layers.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>The forms that I&#8217;m creating need to query a PostgreSQL
database to populate controls. Using the UI init function seems like the thing
to do here. I&#8217;ve managed to populate the controls by setting up a new
connection and executing the query from within this init function.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>However these forms will be opened up all the time, and from
a database administrators point of view I would like cache the database
connection so a new connection is not created every time the form is opened. To
make things more complicated I would like to share this connection across
multiple feature forms within one QGIS user project. I also have a few other
functions relating to the admin of these layers that I currently have in a plug-in
which also needs the same database connection. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>Is there a way to do connection caching with all of this?
I thought about having a singleton class in my plug-in that stores this
connection, but it looks like I can&#8217;t access the plug-in registry from
the PyQGIS api </span></font><font size=2 face=Wingdings><span
style='font-size:10.0pt;font-family:Wingdings'>L</span></font><font size=2
face=Verdana><span style='font-size:10.0pt;font-family:Verdana'><o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>Note I&#8217;m using psycopg2 for the database
connections.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>Thanks,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana'>Jeremy<o:p></o:p></span></font></p>

</div>


<DIV>
<HR>

<DIV>This message contains information, which is confidential and may be subject 
to legal privilege. <BR>If you are not the intended recipient, you must not 
peruse, use, disseminate, distribute or copy this message.<BR>If you have 
received this message in error, please notify us immediately (Phone 0800 665 463 
or <A href="mailto:info@linz.govt.nz">info@linz.govt.nz</A> ) and destroy the 
original message.</DIV>
<DIV>LINZ accepts no responsibility for changes to this email, or for any 
attachments, after its transmission from LINZ.</DIV>
<DIV>&nbsp;</DIV>
<DIV><STRONG>Thank you.</STRONG> <BR></DIV>
<HR>
</DIV>
</body>

</html>