summaryrefslogtreecommitdiff
path: root/src/dic-options/FieldStyleDelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dic-options/FieldStyleDelegate.cpp')
-rw-r--r--src/dic-options/FieldStyleDelegate.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/dic-options/FieldStyleDelegate.cpp b/src/dic-options/FieldStyleDelegate.cpp
new file mode 100644
index 0000000..6efee8c
--- /dev/null
+++ b/src/dic-options/FieldStyleDelegate.cpp
@@ -0,0 +1,35 @@
+#include "FieldStyleDelegate.h"
+#include "../dictionary/Field.h"
+#include "../field-styles/FieldStyleFactory.h"
+
+#include <QComboBox>
+
+FieldStyleDelegate::FieldStyleDelegate(QObject *parent) :
+ QStyledItemDelegate(parent)
+ {
+ }
+
+QWidget* FieldStyleDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const
+ {
+ QComboBox* comboBox = new QComboBox( parent );
+ comboBox->insertItems( 0, FieldStyleFactory::inst()->getStyleNames() );
+ return comboBox;
+ }
+
+void FieldStyleDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+ {
+ QString value = index.model()->data(index, Qt::EditRole).toString();
+ int cbIndex = FieldStyleFactory::inst()->getStyleNames().indexOf( value );
+ QComboBox* comboBox = static_cast<QComboBox*>(editor);
+ comboBox->setCurrentIndex( cbIndex );
+ }
+
+void FieldStyleDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+ {
+ QComboBox* comboBox = static_cast<QComboBox*>(editor);
+ QString value = comboBox->currentText();
+ model->setData(index, value, Qt::EditRole);
+ }
+