summaryrefslogtreecommitdiffstats
path: root/examples/sql/books/bookdelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sql/books/bookdelegate.cpp')
-rw-r--r--examples/sql/books/bookdelegate.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/examples/sql/books/bookdelegate.cpp b/examples/sql/books/bookdelegate.cpp
index 6a42fd2db7..4115f80cf3 100644
--- a/examples/sql/books/bookdelegate.cpp
+++ b/examples/sql/books/bookdelegate.cpp
@@ -62,15 +62,21 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
{
if (index.column() != 5) {
QStyleOptionViewItem opt = option;
- opt.rect.adjust(0, 0, -1, -1); // since we draw the grid ourselves
+ // Since we draw the grid ourselves:
+ opt.rect.adjust(0, 0, -1, -1);
QSqlRelationalDelegate::paint(painter, opt, index);
} else {
const QAbstractItemModel *model = index.model();
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
- (option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled;
+ (option.state & QStyle::State_Active) ?
+ QPalette::Normal :
+ QPalette::Inactive :
+ QPalette::Disabled;
if (option.state & QStyle::State_Selected)
- painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
+ painter->fillRect(
+ option.rect,
+ option.palette.color(cg, QPalette::Highlight));
int rating = model->data(index, Qt::DisplayRole).toInt();
int width = star.width();
@@ -81,7 +87,8 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
painter->drawPixmap(x, y, star);
x += width;
}
- drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
+ // Since we draw the grid ourselves:
+ drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1));
}
QPen pen = painter->pen();
@@ -96,8 +103,8 @@ QSize BookDelegate::sizeHint(const QStyleOptionViewItem &option,
{
if (index.column() == 5)
return QSize(5 * star.width(), star.height()) + QSize(1, 1);
-
- return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1); // since we draw the grid ourselves
+ // Since we draw the grid ourselves:
+ return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1);
}
bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
@@ -112,19 +119,21 @@ bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
int stars = qBound(0, int(0.7 + qreal(mouseEvent->pos().x()
- option.rect.x()) / star.width()), 5);
model->setData(index, QVariant(stars));
- return false; //so that the selection can change
+ // So that the selection can change:
+ return false;
}
return true;
}
-QWidget *BookDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+QWidget *BookDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() != 4)
return QSqlRelationalDelegate::createEditor(parent, option, index);
- // for editing the year, return a spinbox with a range from -1000 to 2100.
+ // For editing the year, return a spinbox with a range from -1000 to 2100.
QSpinBox *sb = new QSpinBox(parent);
sb->setFrame(false);
sb->setMaximum(2100);
@@ -132,4 +141,3 @@ QWidget *BookDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem
return sb;
}
-