[Qgis-developer] vectorlayer new edit type: multi attribute

Denis Rouzaud denis.rouzaud at gmail.com
Thu Jun 28 09:31:34 PDT 2012

Hi all,

As I was very demanding these last 2 days, you probably know I was 
trying to add a new edit type for vector layers.
Suppose you have a table of options, and you can now select from 0 to n 
of this options in a field.
Maybe with an image, it's clearer:

I think my code is ok, it is available here 
https://github.com/3nids/Quantum-GIS and I made a pull request 

However, due to my poor knowledge of QGIS and cpp, there's a few things 
I'm not sure:

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 :
as explained here 
I don't know if we're supposed to let the user check this or if I should 
code this.

2. There is a few lines I copied from the valuerelation edit type 
without understanding what it actually does...
Jurgen just fixed something in this one. I don't get what it's doing.

3. There is some redundancy in the code which updates the columns.
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.

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.

Please let me know what you think. Fill free to give me advice on coding 
as I am beginner.

Happy testing,


PS: a small sample set in postgis

CREATE TABLE test.attributes (id serial NOT NULL);
ALTER TABLE test.attributes ADD COLUMN value varchar(30);
INSERT INTO test.attributes (value) VALUES ('Option 1');
INSERT INTO test.attributes (value) VALUES ('Option 2');
INSERT INTO test.attributes (value) VALUES ('Option 3');
CREATE TABLE test.elements (id serial NOT NULL);
ALTER TABLE test.elements ADD COLUMN options integer[];
SELECT addGeometryColumn('test', 'elements', 'geometry', 21781, 
ALTER TABLE test.elements ADD CONSTRAINT options FOREIGN KEY (options) 
REFERENCES test.attributes (id) MATCH SIMPLE ;
CREATE INDEX fki_options ON test.elements(options);
INSERT INTO test.elements (options,geometry) VALUES 
146263.03710034,555751.6995361 146245.46089015,555750.68004915 
146244.50211359,555750.35404773 146244.19191515)'),21781));
INSERT INTO test.elements (options,geometry) VALUES 
146230.95112375,555727.6687899 146229.26762754,555729.32827011 
146227.68620818,555730.09424706 146226.4618166)'),21781));
INSERT INTO test.elements (options,geometry) VALUES 
146274.95065018,555712.43922982 146274.29916376)'),21781));


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120628/d32fcc03/attachment.html>

More information about the Qgis-developer mailing list