Table model question
Unsolved
General and Desktop
-
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 -
Hi,
Depending on the size of your model you should rather sequentially send the dataChanged signal for the concerned columns.