Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best approach to handle cell properties with model
Forum Updated to NodeBB v4.3 + New Features

Best approach to handle cell properties with model

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 300 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I have my own class that inherits QAbstractTableModel.
    The model is filled using data read from a csv file.

    Then I need to cycle among all rows and columns and set some "properties" for each field (cell).
    Example: for one column I need to query a database to search something and if I find it I will set the property "exists" to true, otherwise "false". Using the Qt::BackgroundColorRole I will change the background to green or red according.

    Questions:

    1. this "parsing" operation should be executed by the model class or by the higher level one (i.e. the QDialog that shows the table) ?
    2. if it's ok to do the parsing within the model class, may I avoid to add hidden columns to store the properties values and add them to the data struct only? This is because if I have, say, 3 properties for each field I need to append three times the column count!
    sierdzioS 1 Reply Last reply
    0
    • M Mark81

      I have my own class that inherits QAbstractTableModel.
      The model is filled using data read from a csv file.

      Then I need to cycle among all rows and columns and set some "properties" for each field (cell).
      Example: for one column I need to query a database to search something and if I find it I will set the property "exists" to true, otherwise "false". Using the Qt::BackgroundColorRole I will change the background to green or red according.

      Questions:

      1. this "parsing" operation should be executed by the model class or by the higher level one (i.e. the QDialog that shows the table) ?
      2. if it's ok to do the parsing within the model class, may I avoid to add hidden columns to store the properties values and add them to the data struct only? This is because if I have, say, 3 properties for each field I need to append three times the column count!
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Mark81 said in Best approach to handle cell properties with model:

      this "parsing" operation should be executed by the model class or by the higher level one (i.e. the QDialog that shows the table) ?

      I'd say it belongs in the model. The view classes are and should be "dumb", they should only display what model tells them.

      if it's ok to do the parsing within the model class, may I avoid to add hidden columns to store the properties values and add them to the data struct only? This is because if I have, say, 3 properties for each field I need to append three times the column count!

      Yep, you can keep that metatada internally, no need for hidden columns. Exactly how you do it will depend on your requirements (if this operation is cheap, you can put the parsing in your model's data() method, if it takes time it will be better to do it once at startup, and store the results in some helper data structure).

      (Z(:^

      M 1 Reply Last reply
      3
      • sierdzioS sierdzio

        @Mark81 said in Best approach to handle cell properties with model:

        this "parsing" operation should be executed by the model class or by the higher level one (i.e. the QDialog that shows the table) ?

        I'd say it belongs in the model. The view classes are and should be "dumb", they should only display what model tells them.

        if it's ok to do the parsing within the model class, may I avoid to add hidden columns to store the properties values and add them to the data struct only? This is because if I have, say, 3 properties for each field I need to append three times the column count!

        Yep, you can keep that metatada internally, no need for hidden columns. Exactly how you do it will depend on your requirements (if this operation is cheap, you can put the parsing in your model's data() method, if it takes time it will be better to do it once at startup, and store the results in some helper data structure).

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @sierdzio said in Best approach to handle cell properties with model:

        Yep, you can keep that metatada internally, no need for hidden columns. Exactly how you do it will depend on your requirements (if this operation is cheap, you can put the parsing in your model's data() method, if it takes time it will be better to do it once at startup, and store the results in some helper data structure).

        Got it! Thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved