blob: bbefbeb4ddf24e0609fdf5ca5425585cfee94247 [file] [log] [blame]
Yingdi Yu8dacdf22013-11-05 23:06:43 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "endorse-combobox-delegate.h"
12
13#include <QComboBox>
14#include <QApplication>
15
16#ifndef Q_MOC_RUN
17#include "logging.h"
Yingdi Yu8dacdf22013-11-05 23:06:43 -080018#endif
19
20INIT_LOGGER("EndorseComboBoxDelegate");
21
22EndorseComboBoxDelegate::EndorseComboBoxDelegate(QObject *parent)
23 : QItemDelegate(parent)
24{
25 m_items.push_back("Not Endorsed");
26 m_items.push_back("Endorsed");
27}
28
29
30QWidget*
31EndorseComboBoxDelegate::createEditor(QWidget *parent,
32 const QStyleOptionViewItem &/* option */,
33 const QModelIndex &/* index */) const
34{
35 QComboBox* editor = new QComboBox(parent);
36 for(unsigned int i = 0; i < m_items.size(); ++i)
37 editor->addItem(m_items[i].c_str());
38 return editor;
39}
40
41void
42EndorseComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
43{
44 QComboBox *comboBox = static_cast<QComboBox*>(editor);
45 int value = index.model()->data(index, Qt::EditRole).toUInt();
Yingdi Yu8dacdf22013-11-05 23:06:43 -080046 comboBox->setCurrentIndex(value);
47}
48
49void
50EndorseComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
51{
52 QComboBox *comboBox = static_cast<QComboBox*>(editor);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080053 model->setData(index, comboBox->currentIndex(), Qt::EditRole);
54}
55
56void
57EndorseComboBoxDelegate::updateEditorGeometry(QWidget *editor,
58 const QStyleOptionViewItem &option,
59 const QModelIndex &/* index */) const
60{
61 editor->setGeometry(option.rect);
62}
63
64void
65EndorseComboBoxDelegate::paint(QPainter *painter,
66 const QStyleOptionViewItem &option,
67 const QModelIndex &index) const
68{
69 QStyleOptionViewItemV4 myOption = option;
70 QString text = m_items[index.model()->data(index, Qt::EditRole).toUInt()].c_str();
71
72 myOption.text = text;
73
74 QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
75}
76
77#if WAF
78#include "endorse-combobox-delegate.moc"
79#include "endorse-combobox-delegate.cpp.moc"
80#endif