mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 21:45:38 +00:00
Refactorisation.
This commit is contained in:
parent
5ad572346b
commit
c422dc6eed
3 changed files with 21 additions and 26 deletions
|
@ -260,6 +260,10 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
|
|||
mDispatcher(this, dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)), document.getUndoStack())
|
||||
|
||||
{
|
||||
CSMWorld::IdTable* model = dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id));
|
||||
const QModelIndex indexToFocus(model->getModelIndex (id.getId(), 0));
|
||||
const int focusedRow = indexToFocus.row();
|
||||
|
||||
QWidget *widget = new QWidget (this);
|
||||
|
||||
setWidget (widget);
|
||||
|
@ -280,9 +284,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
|
|||
|
||||
widget->setLayout (mainLayout);
|
||||
|
||||
QAbstractItemModel *model = document.getData().getTableModel (id);
|
||||
|
||||
int columns = model->columnCount();
|
||||
const int columns = model->columnCount();
|
||||
|
||||
mWidgetMapper = new QDataWidgetMapper (this);
|
||||
mWidgetMapper->setModel (model);
|
||||
|
@ -301,7 +303,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
|
|||
(model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||
|
||||
mDispatcher.makeDelegate(display);
|
||||
QWidget *editor = mDispatcher.makeEditor(display, (model->index (0, i)));
|
||||
QWidget *editor = mDispatcher.makeEditor(display, (model->index (focusedRow, i)));
|
||||
|
||||
if (editor)
|
||||
{
|
||||
|
@ -325,8 +327,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
|
|||
}
|
||||
}
|
||||
|
||||
mWidgetMapper->setCurrentModelIndex (
|
||||
dynamic_cast<CSMWorld::IdTable&> (*model).getModelIndex (id.getId(), 0));
|
||||
mWidgetMapper->setCurrentModelIndex (indexToFocus);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::setEditLock (bool locked)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
void CSVWorld::EnumDelegate::setModelDataImp (QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
if (QComboBox *comboBox = qobject_cast<QComboBox *> (editor))
|
||||
if (QComboBox *comboBox = dynamic_cast<QComboBox *> (editor))
|
||||
{
|
||||
QString value = comboBox->currentText();
|
||||
|
||||
|
@ -42,6 +42,14 @@ CSVWorld::EnumDelegate::EnumDelegate (const std::vector<std::pair<int, QString>
|
|||
|
||||
}
|
||||
|
||||
QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
return createEditor(parent, option, index, CSMWorld::ColumnBase::Display_None);
|
||||
//overloading virtual functions is HARD
|
||||
}
|
||||
|
||||
QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index, CSMWorld::ColumnBase::Display display) const
|
||||
{
|
||||
|
@ -57,24 +65,9 @@ QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent, const QStyleOptio
|
|||
return comboBox;
|
||||
}
|
||||
|
||||
QWidget *CSVWorld::EnumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
if (!index.data(Qt::EditRole).isValid())
|
||||
return 0;
|
||||
|
||||
QComboBox *comboBox = new QComboBox (parent);
|
||||
|
||||
for (std::vector<std::pair<int, QString> >::const_iterator iter (mValues.begin());
|
||||
iter!=mValues.end(); ++iter)
|
||||
comboBox->addItem (iter->second);
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
void CSVWorld::EnumDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const
|
||||
{
|
||||
if (QComboBox *comboBox = qobject_cast<QComboBox *> (editor)) //qobject_cast is faster than dynamic_cast
|
||||
if (QComboBox *comboBox = dynamic_cast<QComboBox *> (editor))
|
||||
{
|
||||
QVariant data = index.data (Qt::EditRole);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <QString>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
|
||||
|
@ -33,12 +34,12 @@ namespace CSVWorld
|
|||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index,
|
||||
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const;
|
||||
const QModelIndex& index) const;
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
const QModelIndex& index,
|
||||
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const;
|
||||
|
||||
virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue