Can I not just do this :
{
if (role == Qt::BackgroundRole) {
if (!value.
isValid() || value.
toString().
isEmpty()) return QColor(Qt
::yellow);
}
}
QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::BackgroundRole) {
const QVariant value = QSqlQueryModel::data(this->index(index.row(), 1), Qt::DisplayRole);
if (!value.isValid() || value.toString().isEmpty()) return QColor(Qt::yellow);
}
return QSqlQueryModel::data(index, role);
}
To copy to clipboard, switch view to plain text mode
What do you think ?? Is it to cryptic to understand what cell I'm testing ?? this->index(index.row() does mean this row... so to me this is easier to read - but what do you think ??
Maybe it is over kill or bad to do this ??? :
{
if (role == Qt::BackgroundRole) {
if (QSqlQueryModel::data(this
->index
(index.
row(),
1), Qt
::DisplayRole).
toString().
isEmpty()) return QColor(Qt
::yellow);
}
}
QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::BackgroundRole) {
if (QSqlQueryModel::data(this->index(index.row(), 1), Qt::DisplayRole).toString().isEmpty()) return QColor(Qt::yellow);
}
return QSqlQueryModel::data(index, role);
}
To copy to clipboard, switch view to plain text mode
Crazy to do a one liner ?? :
{
if (role
== Qt
::BackgroundRole && QSqlQueryModel::data(this
->index
(index.
row(),
1), Qt
::DisplayRole).
toString().
isEmpty()) return QColor(Qt
::yellow);
}
QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::BackgroundRole && QSqlQueryModel::data(this->index(index.row(), 1), Qt::DisplayRole).toString().isEmpty()) return QColor(Qt::yellow);
return QSqlQueryModel::data(index, role);
}
To copy to clipboard, switch view to plain text mode
Bookmarks