mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 01:36:44 +00:00
edit lock for sub views
This commit is contained in:
parent
8dd76b49af
commit
ec1f957e54
6 changed files with 49 additions and 6 deletions
|
@ -165,6 +165,11 @@ void CSVDoc::View::updateDocumentState()
|
||||||
for (int i=0; operations[i]!=-1; ++i)
|
for (int i=0; operations[i]!=-1; ++i)
|
||||||
if (!(state & operations[i]))
|
if (!(state & operations[i]))
|
||||||
mOperations->quitOperation (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)
|
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)
|
CSVWorld::Globals::Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack)
|
||||||
: SubView (id)
|
: 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
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
|
class Table;
|
||||||
|
|
||||||
class Globals : public SubView
|
class Globals : public SubView
|
||||||
{
|
{
|
||||||
|
Table *mTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack);
|
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);
|
SubView (const CSMWorld::UniversalId& id);
|
||||||
|
|
||||||
CSMWorld::UniversalId getUniversalId() const;
|
CSMWorld::UniversalId getUniversalId() const;
|
||||||
|
|
||||||
|
virtual void setEditLock (bool locked) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SubViewFactoryBase
|
struct SubViewFactoryBase
|
||||||
|
|
|
@ -39,12 +39,15 @@ namespace CSVWorld
|
||||||
class CommandDelegate : public QStyledItemDelegate
|
class CommandDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
QUndoStack& mUndoStack;
|
QUndoStack& mUndoStack;
|
||||||
|
bool mEditLock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CommandDelegate (QUndoStack& undoStack, QObject *parent);
|
CommandDelegate (QUndoStack& undoStack, QObject *parent);
|
||||||
|
|
||||||
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
|
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
|
||||||
|
|
||||||
|
void setEditLock (bool locked);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,16 +83,25 @@ QVariant CSVWorld::NastyTableModelHack::getData() const
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::CommandDelegate::CommandDelegate (QUndoStack& undoStack, QObject *parent)
|
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,
|
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
||||||
const QModelIndex& index) const
|
const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
if (!mEditLock)
|
||||||
{
|
{
|
||||||
NastyTableModelHack hack (*model);
|
NastyTableModelHack hack (*model);
|
||||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||||
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack)
|
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack)
|
||||||
|
@ -101,6 +113,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
||||||
for (int i=0; i<columns; ++i)
|
for (int i=0; i<columns; ++i)
|
||||||
{
|
{
|
||||||
CommandDelegate *delegate = new CommandDelegate (undoStack, this);
|
CommandDelegate *delegate = new CommandDelegate (undoStack, this);
|
||||||
|
mDelegates.push_back (delegate);
|
||||||
setItemDelegateForColumn (i, delegate);
|
setItemDelegateForColumn (i, delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,3 +129,9 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
||||||
|
|
||||||
/// \todo make initial layout fill the whole width of the table
|
/// \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
|
#ifndef CSV_WORLD_TABLE_H
|
||||||
#define CSV_WORLD_TABLE_H
|
#define CSV_WORLD_TABLE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
|
@ -13,12 +15,18 @@ namespace CSMWorld
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
|
class CommandDelegate;
|
||||||
|
|
||||||
///< Table widget
|
///< Table widget
|
||||||
class Table : public QTableView
|
class Table : public QTableView
|
||||||
{
|
{
|
||||||
|
std::vector<CommandDelegate *> mDelegates;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack);
|
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack);
|
||||||
|
|
||||||
|
void setEditLock (bool locked);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue