Add functionality of endorsement
diff --git a/src/endorse-combobox-delegate.cpp b/src/endorse-combobox-delegate.cpp
new file mode 100644
index 0000000..e909e3d
--- /dev/null
+++ b/src/endorse-combobox-delegate.cpp
@@ -0,0 +1,83 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#include "endorse-combobox-delegate.h"
+
+#include <QComboBox>
+#include <QApplication>
+
+#ifndef Q_MOC_RUN
+#include "logging.h"
+#include "exception.h"
+#endif
+
+INIT_LOGGER("EndorseComboBoxDelegate");
+
+EndorseComboBoxDelegate::EndorseComboBoxDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+ m_items.push_back("Not Endorsed");
+ m_items.push_back("Endorsed");
+}
+
+
+QWidget*
+EndorseComboBoxDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &/* option */,
+ const QModelIndex &/* index */) const
+{
+ QComboBox* editor = new QComboBox(parent);
+ for(unsigned int i = 0; i < m_items.size(); ++i)
+ editor->addItem(m_items[i].c_str());
+ return editor;
+}
+
+void
+EndorseComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ QComboBox *comboBox = static_cast<QComboBox*>(editor);
+ int value = index.model()->data(index, Qt::EditRole).toUInt();
+ _LOG_DEBUG("value: " << value);
+ comboBox->setCurrentIndex(value);
+}
+
+void
+EndorseComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+ QComboBox *comboBox = static_cast<QComboBox*>(editor);
+ _LOG_DEBUG("currentIndex: " << comboBox->currentIndex());
+ model->setData(index, comboBox->currentIndex(), Qt::EditRole);
+}
+
+void
+EndorseComboBoxDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &/* index */) const
+{
+ editor->setGeometry(option.rect);
+}
+
+void
+EndorseComboBoxDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ QStyleOptionViewItemV4 myOption = option;
+ QString text = m_items[index.model()->data(index, Qt::EditRole).toUInt()].c_str();
+
+ myOption.text = text;
+
+ QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
+}
+
+#if WAF
+#include "endorse-combobox-delegate.moc"
+#include "endorse-combobox-delegate.cpp.moc"
+#endif