[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:
http://postimage.org/image/43fu7kdbn/
I think my code is ok, it is available here
https://github.com/3nids/Quantum-GIS and I made a pull request
https://github.com/qgis/Quantum-GIS/pull/189.
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 :
'{optionid_a,optionid_b,etc}'
as explained here
http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-INPUT
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...
https://github.com/3nids/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5736
<https://github.com/qgis/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5714>
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.
https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L57
and
https://github.com/3nids/Quantum-GIS/blob/master/src/app/qgsattributetypedialog.cpp#L680
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,
Denis
PS: a small sample set in postgis
CREATE SCHEMA test;
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,
'LINESTRING', 2);
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
('{2}',ST_SetSRID(ST_GeomFromText('LINESTRING(555769.76481482
146263.03710034,555751.6995361 146245.46089015,555750.68004915
146244.50211359,555750.35404773 146244.19191515)'),21781));
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));
INSERT INTO test.elements (options,geometry) VALUES
('{}',ST_SetSRID(ST_GeomFromText('LINESTRING(555713.21267068
146274.95065018,555712.43922982 146274.29916376)'),21781));
<https://github.com/qgis/Quantum-GIS/blob/master/src/core/qgsvectorlayer.cpp#L5714>
-------------- 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