1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
QVariant ModeleFenTrafic::data(const QModelIndex &index, int role) const {
static std::set<int> ligneVertes;
switch(role) {
case Qt::BackgroundRole:
int ligneCourante=index.row();
int lignePrecedente=ligneCourante-1;
if(lignePrecedente<=0) lignePrecedente=0;
if(ligneSuivante>=index.model()->rowCount()) ligneSuivante=index.model()->rowCount();
// je ne m'intéresse qu'à la colonne 38
QString valeurPrecedente=index.model()->data(index.model()->index(lignePrecedente,38)).toString();
QStringvaleurCourante=index.model()->data(index.model()->index(ligneCourante,38)).toString();
if(valeurCourante==valeurPrecedente)
{
std::set<int>::iterator it=find(lignesVertes.begin(),lignesVertes.end(),lignePrecedente);
if(it!=lignesVertes.end())
{
lignesVertes.insert(index.row());
QBrush newBackground(Qt::green);
return newBackground;
}
else
{
QBrush newBackground(Qt::blue);
return newBackground;
}
}
else
{
std::set<int>::iterator it=find(lignesVertes.begin(),lignesVertes.end(),lignePrecedente);
if(it!=lignesVertes.end())
{
QBrush newBackground(Qt::blue);
return newBackground;
}
else
{
lignesVertes.insert(index.row());
QBrush newBackground(Qt::green);
return newBackground;
}
}
break;
}
return QSqlQueryModel::data(index,role);
}
|
Partager