diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/dic-options/FieldStyleDelegate.cpp |
Diffstat (limited to 'src/dic-options/FieldStyleDelegate.cpp')
-rw-r--r-- | src/dic-options/FieldStyleDelegate.cpp | 35 |
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); + } + |