// anomalies are underlined in red, otherwise straight paintjob
{
QString value
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
// use background shading to show values we have modified
// and can therefore revert to original
if (rideEditor->table->selectionModel()->isSelected(index) == false &&
rideEditor->isEdited(index.row(), index.column())) {
painter
->fillRect
(option.
rect,
QBrush(QColor(230,
230,
230)));
}
// found items in yellow
if (rideEditor->isFound(index.row(), index.column()) == true) {
}
if (rideEditor->isAnomaly(index.row(), index.column())) {
// wavy line is a pain!
wavy.setUnderlineColor(Qt::red);
cur.selectionStart();
cur.selectionEnd();
cur.setCharFormat(wavy);
// only red background if not selected
if (rideEditor->table->selectionModel()->isSelected(index) == false)
painter
->fillRect
(option.
rect,
QBrush(QColor(255,
230,
230)));
painter->save();
painter->translate(option.rect.x(), option.rect.y());
meh->drawContents(painter);
painter->restore();
delete meh;
} else {
// normal render
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
drawDisplay(painter, myOption, myOption.rect, value);
drawFocus(painter, myOption, myOption.rect);
}
// warning triangle - for high precision numbers
if (rideEditor->isTooPrecise(index.row(), index.column())) {
triangle.putPoints(0, 3, option.rect.x(), option.rect.y(),
option.rect.x()+4, option.rect.y(),
option.rect.x(), option.rect.y()+4);
painter->drawPolygon(triangle);
}
}
// anomalies are underlined in red, otherwise straight paintjob
void CellDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::DisplayRole).toString();
// use background shading to show values we have modified
// and can therefore revert to original
if (rideEditor->table->selectionModel()->isSelected(index) == false &&
rideEditor->isEdited(index.row(), index.column())) {
painter->fillRect(option.rect, QBrush(QColor(230,230,230)));
}
// found items in yellow
if (rideEditor->isFound(index.row(), index.column()) == true) {
painter->fillRect(option.rect, QBrush(QColor(255,255,0)));
}
if (rideEditor->isAnomaly(index.row(), index.column())) {
// wavy line is a pain!
QTextDocument *meh = new QTextDocument(QString(value));
QTextCharFormat wavy;
wavy.setUnderlineStyle(QTextCharFormat::WaveUnderline);
wavy.setUnderlineColor(Qt::red);
QTextCursor cur = meh->find(value);
cur.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
cur.selectionStart();
cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
cur.selectionEnd();
cur.setCharFormat(wavy);
// only red background if not selected
if (rideEditor->table->selectionModel()->isSelected(index) == false)
painter->fillRect(option.rect, QBrush(QColor(255,230,230)));
painter->save();
painter->translate(option.rect.x(), option.rect.y());
meh->drawContents(painter);
painter->restore();
delete meh;
} else {
// normal render
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
drawDisplay(painter, myOption, myOption.rect, value);
drawFocus(painter, myOption, myOption.rect);
}
// warning triangle - for high precision numbers
if (rideEditor->isTooPrecise(index.row(), index.column())) {
QPolygon triangle(3);
triangle.putPoints(0, 3, option.rect.x(), option.rect.y(),
option.rect.x()+4, option.rect.y(),
option.rect.x(), option.rect.y()+4);
painter->setBrush(QBrush(QColor(Qt::darkGreen)));
painter->setPen(QPen(QColor(Qt::darkGreen)));
painter->drawPolygon(triangle);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks