1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

created editwidget

This commit is contained in:
Marek Kochanowicz 2014-03-12 10:21:52 +01:00
parent 865e6b52ae
commit 8d50af547a
2 changed files with 70 additions and 36 deletions

View File

@ -251,68 +251,75 @@ CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher()
} }
/* /*
==============================DialogueSubView========================================== =============================================================EditWidget=====================================================
*/ */
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, CSVWorld::EditWidget::EditWidget(QWidget *parent, const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete) :
bool createAndDelete) : mDispatcher(this, dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)), document.getUndoStack()),
QScrollArea(parent),
SubView (id), mWidgetMapper(NULL),
mDispatcher(this, dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)), document.getUndoStack()) mMainWidget(NULL),
mUndoStack(document.getUndoStack()),
mTable(dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel(id)))
{ {
CSMWorld::IdTable* model = dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)); remake (id);
const QModelIndex indexToFocus(model->getModelIndex (id.getId(), 0)); }
const int focusedRow = indexToFocus.row();
QScrollArea *scrollArea = new QScrollArea(this); void CSVWorld::EditWidget::remake(const CSMWorld::UniversalId& id)
QWidget *widget = new QWidget (scrollArea); {
const QModelIndex indexToFocus(mTable->getModelIndex (id.getId(), 0));
QFrame* line = new QFrame(this); if (mMainWidget)
{
delete mMainWidget;
}
mMainWidget = new QWidget (this);
if (mWidgetMapper)
{
delete mWidgetMapper;
}
mWidgetMapper = new QDataWidgetMapper (this);
mWidgetMapper->setModel(mTable);
mWidgetMapper->setItemDelegate(&mDispatcher);
QFrame* line = new QFrame(mMainWidget);
line->setObjectName(QString::fromUtf8("line")); line->setObjectName(QString::fromUtf8("line"));
line->setGeometry(QRect(320, 150, 118, 3)); line->setGeometry(QRect(320, 150, 118, 3));
line->setFrameShape(QFrame::HLine); line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken); line->setFrameShadow(QFrame::Sunken);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout(mMainWidget);
QGridLayout *unlockedLayout = new QGridLayout; QGridLayout *unlockedLayout = new QGridLayout();
QGridLayout *lockedLayout = new QGridLayout; QGridLayout *lockedLayout = new QGridLayout();
mainLayout->addLayout(lockedLayout, 0); mainLayout->addLayout(lockedLayout, 0);
mainLayout->addWidget(line, 1); mainLayout->addWidget(line, 1);
mainLayout->addLayout(unlockedLayout, 2); mainLayout->addLayout(unlockedLayout, 2);
mainLayout->addStretch(1); mainLayout->addStretch(1);
widget->setLayout (mainLayout);
const int columns = model->columnCount();
mWidgetMapper = new QDataWidgetMapper (this);
mWidgetMapper->setModel (model);
mWidgetMapper->setItemDelegate(&mDispatcher);
int unlocked = 0; int unlocked = 0;
int locked = 0; int locked = 0;
std::vector<QWidget*> editors; const int focusedRow = indexToFocus.row();
const int columns = mTable->columnCount();
for (int i=0; i<columns; ++i) for (int i=0; i<columns; ++i)
{ {
int flags = model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt(); int flags = mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt();
if (flags & CSMWorld::ColumnBase::Flag_Dialogue) if (flags & CSMWorld::ColumnBase::Flag_Dialogue)
{ {
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); (mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
mDispatcher.makeDelegate(display); mDispatcher.makeDelegate(display);
QWidget *editor = mDispatcher.makeEditor(display, (model->index (focusedRow, i))); QWidget *editor = mDispatcher.makeEditor(display, (mTable->index (focusedRow, i)));
if (editor) if (editor)
{ {
editors.push_back(editor);
mWidgetMapper->addMapping (editor, i); mWidgetMapper->addMapping (editor, i);
QLabel* label = new QLabel(model->headerData (i, Qt::Horizontal).toString()); QLabel* label = new QLabel(mTable->headerData (i, Qt::Horizontal).toString(), mMainWidget);
label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
editor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); editor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
if (! (model->flags (model->index (0, i)) & Qt::ItemIsEditable)) if (! (mTable->flags (mTable->index (0, i)) & Qt::ItemIsEditable))
{ {
lockedLayout->addWidget (label, locked, 0); lockedLayout->addWidget (label, locked, 0);
lockedLayout->addWidget (editor, locked, 1); lockedLayout->addWidget (editor, locked, 1);
@ -329,10 +336,24 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
mWidgetMapper->setCurrentModelIndex (indexToFocus); mWidgetMapper->setCurrentModelIndex (indexToFocus);
scrollArea->setMinimumWidth(250); this->setMinimumWidth(300);
scrollArea->setWidget(widget); this->setWidget(mMainWidget);
scrollArea->setWidgetResizable(true); this->setWidgetResizable(true);
setWidget (scrollArea); }
/*
==============================DialogueSubView==========================================
*/
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
bool createAndDelete) :
SubView (id)
{
EditWidget* widget = new EditWidget(this, id, document, false);
setWidget (widget);
} }
void CSVWorld::DialogueSubView::setEditLock (bool locked) void CSVWorld::DialogueSubView::setEditLock (bool locked)

View File

@ -5,6 +5,7 @@
#include <memory> #include <memory>
#include <QAbstractItemDelegate> #include <QAbstractItemDelegate>
#include <QScrollArea>
#include "../doc/subview.hpp" #include "../doc/subview.hpp"
#include "../../model/world/columnbase.hpp" #include "../../model/world/columnbase.hpp"
@ -119,11 +120,23 @@ namespace CSVWorld
}; };
class DialogueSubView : public CSVDoc::SubView class EditWidget : public QScrollArea
{ {
QDataWidgetMapper *mWidgetMapper; QDataWidgetMapper *mWidgetMapper;
DialogueDelegateDispatcher mDispatcher; DialogueDelegateDispatcher mDispatcher;
QWidget* mMainWidget;
CSMWorld::IdTable* mTable;
QUndoStack& mUndoStack;
public:
EditWidget (QWidget *parent, const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete = false);
void remake(const CSMWorld::UniversalId& id);
};
class DialogueSubView : public CSVDoc::SubView
{
public: public:
DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete = false); DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete = false);