blob: 6efee8ce875f6f366594d0efbd97549f305c8a47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}
|