handle color

This commit is contained in:
Marek Kochanowicz 2014-03-10 13:25:01 +01:00
parent 73cb3ac0ed
commit 874847c959
2 changed files with 20 additions and 11 deletions

View file

@ -127,9 +127,14 @@ QSize CSVWorld::DialogueDelegateDispatcher::sizeHint (const QStyleOptionViewItem
QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index)
{
bool hasEnums = CSMWorld::Columns::hasEnums(static_cast<CSMWorld::Columns::ColumnId>(mTable->getColumnId(index.column() ) ) );
if (display == CSMWorld::ColumnBase::Display_Boolean)
QVariant variant = index.data();
if (!variant.isValid())
{
hasEnums = true;
variant = index.data(Qt::DisplayRole);
if (!variant.isValid())
{
return 0;
}
}
QWidget* editor = NULL;
@ -138,11 +143,6 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
{
editor = delegateIt->second->createEditor(dynamic_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, display);
if (display == CSMWorld::ColumnBase::Display_Boolean)
{
connect(editor, SIGNAL(stateChanged(int)), proxy, SLOT(editorDataCommited()));
} else
{
if (hasEnums) //combox is used for all enums
{
connect(editor, SIGNAL(currentIndexChanged (int)), proxy, SLOT(editorDataCommited()));
@ -150,7 +150,6 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
{
connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited()));
}
}
connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)), this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
mProxys.push_back(proxy); //deleted in the destructor
}

View file

@ -13,6 +13,7 @@
#include <QCheckBox>
#include "../../model/world/commands.hpp"
#include <iostream>
CSVWorld::NastyTableModelHack::NastyTableModelHack (QAbstractItemModel& model)
: mModel (model)
@ -126,18 +127,27 @@ void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemMode
QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleOptionViewItem& option,
const QModelIndex& index, CSMWorld::ColumnBase::Display display) const
{
if (!(index.data(Qt::EditRole).isValid() or index.data(Qt::DisplayRole).isValid()))
QVariant variant = index.data();
if (!variant.isValid())
{
return 0;
variant = index.data(Qt::DisplayRole);
if (!variant.isValid())
{
return 0;
}
}
if (display != CSMWorld::ColumnBase::Display_None)
{
if (variant.type() == QVariant::Color)
{
return new QLineEdit(parent);
}
if (display == CSMWorld::ColumnBase::Display_Integer)
{
return new QSpinBox(parent);
}
if (display == CSMWorld::ColumnBase::Display_Integer)
if (display == CSMWorld::ColumnBase::Display_Float)
{
return new QDoubleSpinBox(parent);
}