embelishing

This commit is contained in:
Marek Kochanowicz 2014-03-10 12:04:03 +01:00
parent 361bc55973
commit 73cb3ac0ed
5 changed files with 48 additions and 11 deletions

View file

@ -136,14 +136,20 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display)); std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display));
if (delegateIt != mDelegates.end()) if (delegateIt != mDelegates.end())
{ {
editor = delegateIt->second->createEditor(dynamic_cast<QWidget*>(mParent), QStyleOptionViewItem(), index); editor = delegateIt->second->createEditor(dynamic_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, 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 } 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))); 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 mProxys.push_back(proxy); //deleted in the destructor

View file

@ -42,9 +42,9 @@ CSVWorld::EnumDelegate::EnumDelegate (const std::vector<std::pair<int, QString>
} }
QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option, 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; return 0;
QComboBox *comboBox = new QComboBox (parent); QComboBox *comboBox = new QComboBox (parent);

View file

@ -31,8 +31,10 @@ namespace CSVWorld
EnumDelegate (const std::vector<std::pair<int, QString> >& values, EnumDelegate (const std::vector<std::pair<int, QString> >& values,
QUndoStack& undoStack, QObject *parent); QUndoStack& undoStack, QObject *parent);
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option, virtual QWidget *createEditor(QWidget *parent,
const QModelIndex& index) const; 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; virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;

View file

@ -6,6 +6,11 @@
#include <QUndoStack> #include <QUndoStack>
#include <QMetaProperty> #include <QMetaProperty>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QLineEdit>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QCheckBox>
#include "../../model/world/commands.hpp" #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, 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())) if (!(index.data(Qt::EditRole).isValid() or index.data(Qt::DisplayRole).isValid()))
{
return 0; 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); return QStyledItemDelegate::createEditor (parent, option, index);
} }

View file

@ -101,8 +101,10 @@ namespace CSVWorld
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, virtual void setModelData (QWidget *editor, QAbstractItemModel *model,
const QModelIndex& index) const; const QModelIndex& index) const;
virtual QWidget *createEditor (QWidget *parent, const QStyleOptionViewItem& option, virtual QWidget *createEditor (QWidget *parent,
const QModelIndex& index) const; const QStyleOptionViewItem& option,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const;
void setEditLock (bool locked); void setEditLock (bool locked);