2017-02-04 11:55:49 +01:00
|
|
|
|
#include "ParamTypeDelegate.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "model/TypeSelectionItemModel.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-12-16 15:38:32 +01:00
|
|
|
|
ParamTypeDelegate::ParamTypeDelegate() = default;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-12-16 15:38:32 +01:00
|
|
|
|
ParamTypeDelegate::~ParamTypeDelegate() = default;
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
|
|
|
|
|
void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model)
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2017-02-04 11:55:49 +01:00
|
|
|
|
m_typeSelectionModel = model;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
2017-12-17 19:34:28 +01:00
|
|
|
|
const QStyleOptionViewItem &/*option*/,
|
|
|
|
|
|
const QModelIndex &/*index*/) const
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *w = nullptr;
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
2018-12-16 15:38:32 +01:00
|
|
|
|
auto cmbbx = new QComboBox(parent);
|
2017-02-26 19:29:50 +01:00
|
|
|
|
cmbbx->setMaxVisibleItems(32);
|
2017-02-04 11:55:49 +01:00
|
|
|
|
cmbbx->setModel(m_typeSelectionModel);
|
|
|
|
|
|
w = cmbbx;
|
|
|
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
|
return w;
|
|
|
|
|
|
}
|
2017-02-19 11:12:43 +01:00
|
|
|
|
|
|
|
|
|
|
void ParamTypeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index.column() == 1) {
|
|
|
|
|
|
QComboBox *cmbbx = dynamic_cast<QComboBox*>(editor);
|
|
|
|
|
|
if (cmbbx) {
|
|
|
|
|
|
auto data = index.data();
|
|
|
|
|
|
if (data.canConvert<QString>()) {
|
|
|
|
|
|
QModelIndexList indexes = m_typeSelectionModel->match(
|
2019-02-10 09:10:31 +01:00
|
|
|
|
m_typeSelectionModel->index(0, 0), Qt::DisplayRole, data, 1, Qt::MatchFlags( Qt::MatchExactly ));
|
2017-02-19 11:12:43 +01:00
|
|
|
|
if (!indexes.empty()) {
|
|
|
|
|
|
cmbbx->setCurrentIndex(indexes.at(0).row());
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
cmbbx->setCurrentIndex(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
QStyledItemDelegate::setEditorData(editor, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ParamTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
|
|
|
|
const QModelIndex &index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index.column() == 1) {
|
|
|
|
|
|
QComboBox *cmbbx = dynamic_cast<QComboBox*>(editor);
|
|
|
|
|
|
if (cmbbx) {
|
|
|
|
|
|
auto data = index.data();
|
|
|
|
|
|
if (data.canConvert<QString>()) {
|
|
|
|
|
|
QVariant d = m_typeSelectionModel->data(
|
|
|
|
|
|
m_typeSelectionModel->index(cmbbx->currentIndex(), 0));
|
|
|
|
|
|
model->setData(index, d);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QStyledItemDelegate::setModelData(editor, model, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// triggered by editing finished from editor
|
|
|
|
|
|
void ParamTypeDelegate::commitAndCloseEditor()
|
|
|
|
|
|
{
|
|
|
|
|
|
// StarEditor *editor = qobject_cast<StarEditor *>(sender());
|
|
|
|
|
|
// emit commitData(editor);
|
|
|
|
|
|
// emit closeEditor(editor);
|
|
|
|
|
|
}
|