<div dir="ltr"><div><div><div><div><div>Dear André,<br><br></div>I asked for the same problem months ago without obtaining any answer. As far as I know, there is no QGIS feature implemented that allows you to achieve what you are looking for.<br><br></div>So I decided to dive into my underlying PostgreSQL databse structure. The solution I chose was the following: Two reference tables with data description and one table with data for the user affected by one constraint.<br><br></div><u>Reference table for attribute 1 (ATTR1_TABLE)</u><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">--  ----------------</span></span><br><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace"></span>ID  Textf</span><br><span style="font-family:monospace,monospace">--  ----------------</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">01  Agriculture (01)</span><br><span style="font-family:monospace,monospace"></span></div></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02  Forest (02)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">--  ----------------<br></span><span style="font-family:monospace,monospace"></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"></span></div><div><br><u>Reference table for attribute 2 (ATTR2_TABLE)</u><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">-----  --------------<br></span></span><div><span style="font-family:monospace,monospace"></span></div><span style="font-family:monospace,monospace">ID     Textf<br>-----  --------------<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">01.01  Corn (01.01)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">01.02  Wheat (01.02)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02.01  Pines (02.01)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02.02  Olives (02.02)<br></span></div><div><div style="margin-left:40px"><span style="font-family:monospace,monospace">-----  --------------</span><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"></span></div><br></div><div><u>Structure of the table containing the data to be shown to the final user (DATA_TABLE)</u><br></div><div><div style="margin-left:40px"><span style="font-family:monospace,monospace">attrib1_cod: character varying(9)</span><br><span style="font-family:monospace,monospace">attrib1_desc: character varying(100)</span><br><span style="font-family:monospace,monospace">attrib2_cod: character varying(9)</span><br><span style="font-family:monospace,monospace">attrib2_desc: character varying(100)</span><br></div><br>Then I stablished the appropriate <u>database constraint</u>:<br><br><div style="margin-left:40px"><span style="font-family:monospace,monospace">ALTER TABLE DATA_TABLE</span><br><span style="font-family:monospace,monospace">  ADD CONSTRAINT data_table_cc_attr2 CHECK (attrib2_cod IS NULL OR attrib2_cod::text = ''::text OR "substring"(attrib2_cod::text, '^..'::text) = attrib1_cod::text);</span><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"></span></div><br></div><div>With this constraint, you ensure that the data to be introduced in ATTR2_TABLE ID field must contain in the string beginning one of the values present in ATTRIB1_TABLE ID field. So, if your user has selected attrib1_cod/attrib1_desc 01/Agriculture (01) for DATA_TABLE, then, when fullfilling attrib2_cod field he only can choose the values 01.01 or 01.02, because both of them start with the string '01'. <br><br></div><div>Well, he can really choose any value for attrib2_cod, but only the appropriate ones won't throw insertion errors.<br><br></div><div>The problem with this workaround is that the user can choose any value for attr2_cod field. But, if you decide to show him just the descriptive text fields, he can easily see which ones are proper values (because in the tex field all records end with the numeric code).<br><br></div><div>I've personally decided to use just the numeric values for my users. So, under QGIS, and through a widget (value map), I show my users the fields attrib1_cod and attrib2_cod, but with the values taken from the text fields:<br></div><div><br><u>Value map widget for attrib1_cod</u><br></div><div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">-----  ----------------</span></span><br><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace"></span>Value  Description</span><br><span style="font-family:monospace,monospace">-----  ----------------</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">01     Agriculture (01)</span><br><span style="font-family:monospace,monospace"></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02     Forest (02)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">--     ----------------</span><br></div> </div><div>When the user selects from the drop down list the description 'Agriculture (01)', he is really selecting the value '01' for attrib1_cod. The same applies to attrib2_cod:<br><br><u>Value map widget for attrib2_cod</u><br><div style="margin-left:40px"><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">-----  --------------<br></span></span><div><span style="font-family:monospace,monospace"></span></div><span style="font-family:monospace,monospace">Value  Description<br>-----  --------------<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">01.01  Corn (01.01)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">01.02  Wheat (01.02)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02.01  Pines (02.01)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">02.02  Olives (02.02)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">-----  --------------</span><br></div><br></div><div>And finally, in order not to ask the user to fullfill the field attrib*_desc (cause he has previously fullfilled attrib*_cod but from descriptive values), I have two more triggers and trigger functions whose mission is to fill in the descriptive fields provided the code fields have been modified:<br><br></div><div><u>Trigger for attrib1_desc on table DATA_TABLE</u><br><div style="margin-left:40px"><span style="font-family:monospace,monospace">CREATE TRIGGER update_attrib1_desc</span><br><span style="font-family:monospace,monospace">  BEFORE INSERT OR UPDATE</span><br><span style="font-family:monospace,monospace">  ON DATA_TABLE</span><br><span style="font-family:monospace,monospace">  FOR EACH ROW</span><br><span style="font-family:monospace,monospace">  EXECUTE PROCEDURE update_attrib1_desc();</span><br></div><br></div><div><u>Trigger function for called by the previous trigger</u><br><div style="margin-left:40px"><span style="font-family:monospace,monospace">CREATE OR REPLACE FUNCTION update_attrib1_desc()</span><br><span style="font-family:monospace,monospace">  RETURNS trigger AS</span><br><span style="font-family:monospace,monospace">$BODY$</span><br><span style="font-family:monospace,monospace">  DECLARE</span><br><span style="font-family:monospace,monospace">  BEGIN</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">    IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">      NEW.attrib1_desc := (SELECT Textf FROM ATTR1_TABLE WHERE ID = NEW.attrib1_cod);</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">      RETURN NEW;</span><br><span style="font-family:monospace,monospace">    ELSE</span><br><span style="font-family:monospace,monospace">      RETURN NULL;</span><br><span style="font-family:monospace,monospace">    END IF;</span><br><span style="font-family:monospace,monospace">  END;</span><br><span style="font-family:monospace,monospace">$BODY$</span><br><span style="font-family:monospace,monospace">  LANGUAGE plpgsql VOLATILE</span><br><span style="font-family:monospace,monospace">  COST 100;</span><br></div></div><div><br></div><div>So each time an attrib1_cod field is entered or updated, the trigger seeks for the appropriate attrib1_desc field and writes it into attrib1_desc field.<br><br>And the same for attib2_desc:<br><br><div><u>Trigger for attrib2_desc on table DATA_TABLE</u><br><div style="margin-left:40px"><span style="font-family:monospace,monospace">CREATE TRIGGER update_attrib2_desc</span><br><span style="font-family:monospace,monospace">  BEFORE INSERT OR UPDATE</span><br><span style="font-family:monospace,monospace">  ON DATA_TABLE</span><br><span style="font-family:monospace,monospace">  FOR EACH ROW</span><br><span style="font-family:monospace,monospace">  EXECUTE PROCEDURE update_attrib2_desc();</span><br></div><br></div><u>Trigger function for called by the previous trigger</u><br><span style="font-family:monospace,monospace">CREATE OR REPLACE FUNCTION update_attrib2_desc()</span><br><span style="font-family:monospace,monospace">  RETURNS trigger AS</span><br><span style="font-family:monospace,monospace">$BODY$</span><br><span style="font-family:monospace,monospace">  DECLARE</span><br><span style="font-family:monospace,monospace">  BEGIN</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">    IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">      NEW.attrib2_desc := (SELECT Textf FROM ATTR2_TABLE WHERE ID = NEW.attrib2_cod);</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">      RETURN NEW;</span><br><span style="font-family:monospace,monospace">    ELSE</span><br><span style="font-family:monospace,monospace">      RETURN NULL;</span><br><span style="font-family:monospace,monospace">    END IF;</span><br><span style="font-family:monospace,monospace">  END;</span><br><span style="font-family:monospace,monospace">$BODY$</span><br><span style="font-family:monospace,monospace">  LANGUAGE plpgsql VOLATILE</span><br><span style="font-family:monospace,monospace">  COST 100;</span><br><br><br></div><div>A little bit confusing, but I haven't found any other way to solve the problem...<br><br></div><div>Best regards.<br><br><br></div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-23 12:19 GMT+02:00 ALT SHN <span dir="ltr"><<a href="mailto:i.geografica@alt-shn.org" target="_blank">i.geografica@alt-shn.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">I am looking for a way to implement conditional value mapping in QGIS. This means that the values available in attribute number 2 depend on the value provided in attribute 1.</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Example:</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">If the user enters "agriculture" in attribute 1, for attribute 2 only "corn" or "wheat" will be available.</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Instead, if the user enters "forest" in attribute 1, for attribute 2 only "pines" or "olives" will be available.</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">And so on...</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Apparently this is not doable just using the QGIS widget expression builder, but I am not sure. Here's a screencast to help visualize. The problem is that if for "class" I pick other than "Agri_Field", for the "color_aggri" attribute the same possible values appear.</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)"><img src="http://i.stack.imgur.com/eqhY1.png" alt="enter image description here" style="margin: 0px; padding: 0px; border: 0px none; vertical-align: baseline; max-width: 630px;"></p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Thanks in advance for any hints!</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)"><br></p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Regards,</p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)"><br></p><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:14px;vertical-align:baseline;clear:both;color:rgb(51,51,51);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:18px;background-color:rgba(248,248,248,0.6)">Andre</p></div><div><br></div><div><br></div><div><br clear="all"><div><br></div>-- <br><div><div dir="ltr">---------------------------------------------------------------<br><img src="https://1.bp.blogspot.com/-tUOfxWaFyQ8/UKN4jZdmLlI/AAAAAAAAA50/mMZ01ZDGCkI/s280/Logotipo-SHN-novo-02.gif" height="102" width="200"><br><br><span><font color="#999999"><b>Sociedade de História Natural</b><br><font>Departamento de Informa</font></font></span><span><font color="#999999"><font><span>ção Geográfica<br></span>Polígono Industrial do Alto do Amial<br>Pav.H02 e H06</font><br><br><a href="mailto:laboratorio@alt-shn.org" target="_blank">i.geografica<font color="#999999">@</font>alt-shn.org</a><br><a href="http://www.shn.pt" target="_blank">www.shn.pt</a><br><a href="http://www.alt-shn.blogspot.com" target="_blank">www.alt-shn.blogspot.com</a></font></span><div>
<span><font color="#999999"><a href="https://www.facebook.com/SociedadeDeHistoriaNatural?ref=hl" target="_blank">Facebook</a><br><br>TLM: <a value="+351964138188">964138188</a></font></span></div><br></div></div>
</div></div>
<br>_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><br>
<table style="border-width:1px 2px 2px 1px;border-style:solid;border-color:black;font-size:11pt;width:470px;color:black" border="0" cellpadding="2" cellspacing="2">
  <tbody>
  <tr>
    <td rowspan="2" align="center" valign="center" width="35%"><a href="http://www.ucm.es/" target="_blank"><img src="http://www.ucm.es/nodes/web/00media/img/ucm-ws.png" align="middle" border="0" height="70" width="70"></a>   </td>
    <td colspan="3" align="center" bgcolor="#a50000"><a href="http://www.ucm.es/" target="_blank"><font style="text-decoration:none" color="white" face="Verdana" size="2"><b>Universidad Complutense de Madrid</b></font></a>      </td>
  </tr>
  <tr>
    <td colspan="3" align="center"><font color="#000099" face="Verdana" size="2">Dr. <b>Víctor Manuel Herreros Villanueva</b> </font><br><font color="#000099" face="Verdana" size="1">Jefe de Proyecto</font>
        </td>
  </tr>
  <tr>
    <td colspan="2" align="left"><font color="#000099" face="Verdana" size="2"><b>Gestión de Espacios<br>Data Warehouse</b></font><br>
       
        </td>
    <td colspan="2" align="right" width="48%"><font color="#336699" face="Verdana" size="2">Jardín Botánico</font><font color="#336699" face="Verdana" size="2"><br>
      Av. Complutense s/n<br>28040 Madrid</font>
        </td>
  </tr>
  <tr>
    <td colspan="2" align="left"><font color="#000099" face="Verdana" size="1"><i>Tfn. 
      (+34) 91 394 <b>7275</b><br>
      Fax. (+34) 91 394 <b>4773</b></i> </font>
        </td>
    <td align="right"><a href="mailto:vherreros@ucm.es" target="_blank"><font style="text-decoration:none" color="#000099" face="Verdana" size="1">vherreros@ucm.es</font></a>
        </td>
  </tr>
  </tbody>
</table>
<p><br>
</p>
</div></div>
</div></div></div></div></div>