PDA

View Full Version : Inserting MySQL geometry types into a QAbstractModel.



Mookie
9th April 2011, 02:53
I am using QMYSQL3 plugin to work with a MySQL database. I am also using the Model/View architecture as much as possible.

Does anyone know of a way to format the QVariant parameter of setData() to accept a geometry datatype?

I have something like this
PolyFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')

Obviously, my goal is to avoid writing the SQL manipulations by hand and let the model do the work.

d_stranz
9th April 2011, 18:16
I'm not sure what you're asking here. QPolygon and other Qt geometric objects are registered as QMetaType types, and have a QVariant operator. Thus they should be acceptable to the model's setData() method without extra code on your part.

Mookie
9th April 2011, 22:39
QPolygon is a valid QVariant type, yes.
QPolygonF is not. (No problem though, I registered it as a QVariant::UserType myself)

Neither is mapped to the MySQL POLYGON data type in the mysql drivers so, as a result, the sqlmodel classes don't know what to do with them.

I am asking if anyone has experience in easy ways for me to continue using the model/view architecture.
Must I ditch the POLYGON type and just roll my own Point table with some foreign key? I lose the MySQL geometric searching abilities if I do this.
Maybe someone has dealt with this before and modified the models to convince them to allow inserts, updates, and deletes of rows that contain these datatypes?

It appears from my preliminary pass through the source that this is a function of the MySQL driver. Deriving from the driver and adding QVariant(QPolygonF) support isn't going to be a good use of my time.

d_stranz
12th April 2011, 06:26
Ok, I think I understand the issue. What does the MySQL POLYGON type actually look like? Is it the ASCII text representation you originally posted or some other binary format? In either case , I think it would be relatively straightforward in the model's data() / setData() methods to do the mapping from / to the internal representation.

I don't have much experience in mapping from SQL into models, so I'm probably missing something. Sorry not to be of much help.