From 874847c959a7e4e93902b1dd891e06d823182f36 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 10 Mar 2014 13:25:01 +0100 Subject: [PATCH] handle color --- apps/opencs/view/world/dialoguesubview.cpp | 15 +++++++-------- apps/opencs/view/world/util.cpp | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index c4e9b805c7..6a37ce59c9 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -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(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(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 } diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 7e8cddd1f4..5da616ebb8 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -13,6 +13,7 @@ #include #include "../../model/world/commands.hpp" +#include 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); }