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. Table model question
Qt 6.11 is out! See what's new in the release blog

Table model question

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 234 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I have a table model which has many columns of data. Some to them display differently depending on the setting of a variables in a class/struct stored in mydata (a vector).

    So, my data mf has code that looks like:

                case Column::dXCol:
                    if (mydata[row].m_PictureType != PICTURETYPE_LIGHTFRAME)
                        return QString("N/A");
                    else
                    {
                        if (mydata[row].m_bDeltaComputed)
                            return QString("%1").arg(mydata[row].m_dX, 0, 'f', 2);
                        else
                            return QString("NC");
                    };
                    break;
                case Column::dYCol:
                    if (mydata[row].m_PictureType != PICTURETYPE_LIGHTFRAME)
                        return QString("N/A");
                    else
                    {
                        if (mydata[row].m_bDeltaComputed)
                            return QString("%1").arg(mydata[row].m_dY, 0, 'f', 2);
                        else
                            return QString("NC");
                    };
                    break;
                case Column::AngleCol:
                    if (mydata[row].m_PictureType != PICTURETYPE_LIGHTFRAME)
                        return QString("N/A");
                    else
                    {
                        if (mydata[row].m_bDeltaComputed)
                            return QString("%1 °").arg(mydata[row].m_fAngle * 180.0 / M_PI, 0, 'f', 2);
                        else
                            return QString("NC");
                    };
                    break;
    

    So, if m_bDeltaComputed is changed, the display of a number of columns needs to be refreshed.

    What's the best way to handle this?

    I thought of adding a mf that tells the TableView that ALL the model data has changed which I think should look like:

            int rowCount(const QModelIndex& parent) const
            {
                // Return number of images we know about
                return static_cast<int>(mydata.size());
            };
    
            int columnCount(const QModelIndex& parent) const
            {
                // Pretty simple really
                return static_cast<int>(Column::MAX_COLS);
            };
           void emitAllChanged()
            {
                QModelIndex start{ QAbstractItemModel::createIndex(0, 0)};
                QModelIndex end{ QAbstractItemModel::createIndex(rowCount(start), columnCount(start)) };
                emit dataChanged(start, end);
            }
    

    Would that heavy handed approach work (and did I even code it correctly)?

    Is there a better approach?

    Many thanks
    David

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Depending on the size of your model you should rather sequentially send the dataChanged signal for the concerned columns.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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