From 73cb3ac0ed3f469877f04bebf26861b8bce43dbe Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 10 Mar 2014 12:04:03 +0100 Subject: [PATCH] embelishing --- apps/opencs/view/world/dialoguesubview.cpp | 14 ++++++++--- apps/opencs/view/world/enumdelegate.cpp | 4 +-- apps/opencs/view/world/enumdelegate.hpp | 6 +++-- apps/opencs/view/world/util.cpp | 29 +++++++++++++++++++++- apps/opencs/view/world/util.hpp | 6 +++-- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 6145c9dfa7..c4e9b805c7 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -136,14 +136,20 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase:: std::map::iterator delegateIt(mDelegates.find(display)); if (delegateIt != mDelegates.end()) { - editor = delegateIt->second->createEditor(dynamic_cast(mParent), QStyleOptionViewItem(), index); + editor = delegateIt->second->createEditor(dynamic_cast(mParent), QStyleOptionViewItem(), index, display); DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, display); - if (hasEnums) //combox is used for all enums + if (display == CSMWorld::ColumnBase::Display_Boolean) { - connect(editor, SIGNAL(currentIndexChanged (int)), proxy, SLOT(editorDataCommited())); + connect(editor, SIGNAL(stateChanged(int)), proxy, SLOT(editorDataCommited())); } else { - connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited())); + if (hasEnums) //combox is used for all enums + { + connect(editor, SIGNAL(currentIndexChanged (int)), proxy, SLOT(editorDataCommited())); + } else + { + 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/enumdelegate.cpp b/apps/opencs/view/world/enumdelegate.cpp index a6089a1b36..858458b37b 100644 --- a/apps/opencs/view/world/enumdelegate.cpp +++ b/apps/opencs/view/world/enumdelegate.cpp @@ -42,9 +42,9 @@ CSVWorld::EnumDelegate::EnumDelegate (const std::vector } QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option, - const QModelIndex& index) const + const QModelIndex& index, CSMWorld::ColumnBase::Display display) const { - if (!index.data().isValid()) + if (!index.data(Qt::EditRole).isValid() && !index.data(Qt::DisplayRole).isValid()) return 0; QComboBox *comboBox = new QComboBox (parent); diff --git a/apps/opencs/view/world/enumdelegate.hpp b/apps/opencs/view/world/enumdelegate.hpp index ac07f3d1ed..8bd96a6f20 100644 --- a/apps/opencs/view/world/enumdelegate.hpp +++ b/apps/opencs/view/world/enumdelegate.hpp @@ -31,8 +31,10 @@ namespace CSVWorld EnumDelegate (const std::vector >& values, QUndoStack& undoStack, QObject *parent); - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option, - const QModelIndex& index) const; + virtual QWidget *createEditor(QWidget *parent, + const QStyleOptionViewItem& option, + const QModelIndex& index, + CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const; virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const; diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 74aaeb6f0e..7e8cddd1f4 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -6,6 +6,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "../../model/world/commands.hpp" @@ -119,10 +124,32 @@ void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemMode } QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleOptionViewItem& option, - const QModelIndex& index) const + const QModelIndex& index, CSMWorld::ColumnBase::Display display) const { if (!(index.data(Qt::EditRole).isValid() or index.data(Qt::DisplayRole).isValid())) + { return 0; + } + + if (display != CSMWorld::ColumnBase::Display_None) + { + if (display == CSMWorld::ColumnBase::Display_Integer) + { + return new QSpinBox(parent); + } + if (display == CSMWorld::ColumnBase::Display_Integer) + { + return new QDoubleSpinBox(parent); + } + if (display == CSMWorld::ColumnBase::Display_String) + { + return new QLineEdit(parent); + } + if (display == CSMWorld::ColumnBase::Display_Boolean) + { + return new QCheckBox(parent); + } + } return QStyledItemDelegate::createEditor (parent, option, index); } diff --git a/apps/opencs/view/world/util.hpp b/apps/opencs/view/world/util.hpp index 23b9fcfac1..814f09d3a2 100644 --- a/apps/opencs/view/world/util.hpp +++ b/apps/opencs/view/world/util.hpp @@ -101,8 +101,10 @@ namespace CSVWorld virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const; - virtual QWidget *createEditor (QWidget *parent, const QStyleOptionViewItem& option, - const QModelIndex& index) const; + virtual QWidget *createEditor (QWidget *parent, + const QStyleOptionViewItem& option, + const QModelIndex& index, + CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const; void setEditLock (bool locked);