mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-15 09:39:53 +00:00
edit lock for sub views
This commit is contained in:
parent
8dd76b49af
commit
ec1f957e54
@ -165,6 +165,11 @@ void CSVDoc::View::updateDocumentState()
|
||||
for (int i=0; operations[i]!=-1; ++i)
|
||||
if (!(state & operations[i]))
|
||||
mOperations->quitOperation (operations[i]);
|
||||
|
||||
QList<CSVWorld::SubView *> subViews = findChildren<CSVWorld::SubView *>();
|
||||
|
||||
for (QList<CSVWorld::SubView *>::iterator iter (subViews.begin()); iter!=subViews.end(); ++iter)
|
||||
(*iter)->setEditLock (state && CSMDoc::Document::State_Locked);
|
||||
}
|
||||
|
||||
void CSVDoc::View::updateProgress (int current, int max, int type, int threads)
|
||||
|
@ -6,7 +6,10 @@
|
||||
CSVWorld::Globals::Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack)
|
||||
: SubView (id)
|
||||
{
|
||||
QTableView *table = new Table (id, data, undoStack);
|
||||
setWidget (mTable = new Table (id, data, undoStack));
|
||||
}
|
||||
|
||||
setWidget (table);
|
||||
void CSVWorld::Globals::setEditLock (bool locked)
|
||||
{
|
||||
mTable->setEditLock (locked);
|
||||
}
|
@ -7,11 +7,17 @@ class QUndoStack;
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class Table;
|
||||
|
||||
class Globals : public SubView
|
||||
{
|
||||
Table *mTable;
|
||||
|
||||
public:
|
||||
|
||||
Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack);
|
||||
|
||||
virtual void setEditLock (bool locked);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ namespace CSVWorld
|
||||
SubView (const CSMWorld::UniversalId& id);
|
||||
|
||||
CSMWorld::UniversalId getUniversalId() const;
|
||||
|
||||
virtual void setEditLock (bool locked) = 0;
|
||||
};
|
||||
|
||||
struct SubViewFactoryBase
|
||||
|
@ -39,12 +39,15 @@ namespace CSVWorld
|
||||
class CommandDelegate : public QStyledItemDelegate
|
||||
{
|
||||
QUndoStack& mUndoStack;
|
||||
bool mEditLock;
|
||||
|
||||
public:
|
||||
|
||||
CommandDelegate (QUndoStack& undoStack, QObject *parent);
|
||||
|
||||
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
|
||||
|
||||
void setEditLock (bool locked);
|
||||
};
|
||||
|
||||
}
|
||||
@ -80,15 +83,24 @@ QVariant CSVWorld::NastyTableModelHack::getData() const
|
||||
}
|
||||
|
||||
CSVWorld::CommandDelegate::CommandDelegate (QUndoStack& undoStack, QObject *parent)
|
||||
: QStyledItemDelegate (parent), mUndoStack (undoStack)
|
||||
: QStyledItemDelegate (parent), mUndoStack (undoStack), mEditLock (false)
|
||||
{}
|
||||
|
||||
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
NastyTableModelHack hack (*model);
|
||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
||||
if (!mEditLock)
|
||||
{
|
||||
NastyTableModelHack hack (*model);
|
||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
||||
}
|
||||
///< \todo provide some kind of feedback to the user, indicating that editing is currently not possible.
|
||||
}
|
||||
|
||||
void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
||||
{
|
||||
mEditLock = locked;
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +113,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
||||
for (int i=0; i<columns; ++i)
|
||||
{
|
||||
CommandDelegate *delegate = new CommandDelegate (undoStack, this);
|
||||
mDelegates.push_back (delegate);
|
||||
setItemDelegateForColumn (i, delegate);
|
||||
}
|
||||
|
||||
@ -115,4 +128,10 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
||||
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
|
||||
/// \todo make initial layout fill the whole width of the table
|
||||
}
|
||||
|
||||
void CSVWorld::Table::setEditLock (bool locked)
|
||||
{
|
||||
for (std::vector<CommandDelegate *>::iterator iter (mDelegates.begin()); iter!=mDelegates.end(); ++iter)
|
||||
(*iter)->setEditLock (locked);
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#ifndef CSV_WORLD_TABLE_H
|
||||
#define CSV_WORLD_TABLE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
class QUndoStack;
|
||||
@ -13,12 +15,18 @@ namespace CSMWorld
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class CommandDelegate;
|
||||
|
||||
///< Table widget
|
||||
class Table : public QTableView
|
||||
{
|
||||
std::vector<CommandDelegate *> mDelegates;
|
||||
|
||||
public:
|
||||
|
||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack);
|
||||
|
||||
void setEditLock (bool locked);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user