<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi all,<br>
    <br>
    As I was very demanding these last 2 days, you probably know I was
    trying to add a new edit type for vector layers.<br>
    Suppose you have a table of options, and you can now select from 0
    to n of this options in a field.<br>
    Maybe with an image, it's clearer:<br>
    <a class="moz-txt-link-freetext" href="http://postimage.org/image/43fu7kdbn/">http://postimage.org/image/43fu7kdbn/</a><br>
    <br>
    I think my code is ok, it is available here
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a href="https://github.com/3nids/Quantum-GIS">https://github.com/3nids/Quantum-GIS</a>
    and I made a pull request
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a href="https://github.com/qgis/Quantum-GIS/pull/189">https://github.com/qgis/Quantum-GIS/pull/189</a>.<br>
    <br>
    However, due to my poor knowledge of QGIS and cpp, there's a few
    things I'm not sure:<br>
    <br>
    1. I do not check the type of the field. Basically it should be
    either integer[] or string. My code is writing the field as a string
    :<br>
    '{optionid_a,optionid_b,etc}'<br>
    as explained here
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a
href="http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-INPUT">http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-INPUT</a><br>
    I don't know if we're supposed to let the user check this or if I
    should code this.<br>
    <br>
    2. There is a few lines I copied from the valuerelation edit type
    without understanding what it actually does...<br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a
href="https://github.com/qgis/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5714">https://github.com/3nids/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5736</a><br>
    Jurgen just fixed something in this one. I don't get what it's
    doing.<br>
    <br>
    3. There is some redundancy in the code which updates the columns. <br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a
href="https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L57">https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L57</a><br>
    and<br>
    <meta http-equiv="content-type" content="text/html;
      charset=ISO-8859-1">
    <a
href="https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L680">https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L680</a><br>
    But, there might be something to be done with signal mapping but
    that's beyond my competences. I tried this once in python with no
    success.<br>
    <br>
    4. More on the postgres side, there is something annoying:
    apparently the foreign key is not working: you can delete an option
    even if it's used in some features.<br>
    <br>
    Please let me know what you think. Fill free to give me advice on
    coding as I am beginner.<br>
    <br>
    Happy testing,<br>
    <br>
    Denis<br>
    <br>
    PS: a small sample set in postgis<br>
    <br>
    CREATE SCHEMA test;<br>
    CREATE TABLE test.attributes (id serial NOT NULL);<br>
    ALTER TABLE test.attributes ADD COLUMN value varchar(30);<br>
    INSERT INTO test.attributes (value) VALUES ('Option 1');<br>
    INSERT INTO test.attributes (value) VALUES ('Option 2');<br>
    INSERT INTO test.attributes (value) VALUES ('Option 3');<br>
    CREATE TABLE test.elements (id serial NOT NULL);<br>
    ALTER TABLE test.elements ADD COLUMN options integer[];<br>
    SELECT addGeometryColumn('test', 'elements', 'geometry', 21781,
    'LINESTRING', 2);<br>
    ALTER TABLE test.elements ADD CONSTRAINT options FOREIGN KEY
    (options) REFERENCES test.attributes (id) MATCH SIMPLE ;<br>
    CREATE INDEX fki_options ON test.elements(options);<br>
    INSERT INTO test.elements (options,geometry) VALUES
    ('{2}',ST_SetSRID(ST_GeomFromText('LINESTRING(555769.76481482
    146263.03710034,555751.6995361 146245.46089015,555750.68004915
    146244.50211359,555750.35404773 146244.19191515)'),21781));<br>
    INSERT INTO test.elements (options,geometry) VALUES
    ('{1,2,3}',ST_SetSRID(ST_GeomFromText('LINESTRING(555724.04334769
    146230.95112375,555727.6687899 146229.26762754,555729.32827011
    146227.68620818,555730.09424706 146226.4618166)'),21781));<br>
    INSERT INTO test.elements (options,geometry) VALUES
    ('{}',ST_SetSRID(ST_GeomFromText('LINESTRING(555713.21267068
    146274.95065018,555712.43922982 146274.29916376)'),21781));<br>
    <br>
    <br>
    <br>
    <br>
    <a
href="https://github.com/qgis/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5714"></a>
  </body>
</html>