Results 1 to 4 of 4

Thread: Inserting MySQL geometry types into a QAbstractModel.

  1. #1
    Join Date
    Jun 2006
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9

    Default Inserting MySQL geometry types into a QAbstractModel.

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,341
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Inserting MySQL geometry types into a QAbstractModel.

    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.

  3. #3
    Join Date
    Jun 2006
    Posts
    43
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9

    Default Re: Inserting MySQL geometry types into a QAbstractModel.

    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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,341
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Inserting MySQL geometry types into a QAbstractModel.

    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.

Similar Threads

  1. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 17:40
  2. Inserting blob into mysql using QT?
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 31st August 2010, 05:37
  3. Replies: 4
    Last Post: 10th December 2009, 17:37
  4. QGraphicsLayout::geometry()
    By isutruk in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 16:43
  5. Lazy population of QAbstractModel
    By bastien in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 21:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.