1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 05:53:50 +00:00

moved change lock from ScriptSubView to ScriptEdit

This commit is contained in:
Marc Zinnschlag 2014-08-21 14:50:13 +02:00
parent 2f08d44313
commit d4981c3037
4 changed files with 55 additions and 35 deletions

View file

@ -9,10 +9,22 @@
#include "../../model/world/universalid.hpp"
#include "../../model/world/tablemimedata.hpp"
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
{
++mEdit.mChangeLocked;
}
CSVWorld::ScriptEdit::ChangeLock::~ChangeLock()
{
--mEdit.mChangeLocked;
}
CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& document) :
QTextEdit (parent),
mDocument (document),
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive),
mChangeLocked (0)
{
setAcceptRichText (false);
setLineWrapMode (QTextEdit::NoWrap);
@ -50,6 +62,11 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& docum
<<CSMWorld::UniversalId::Type_Region;
}
bool CSVWorld::ScriptEdit::isChangeLocked() const
{
return mChangeLocked!=0;
}
void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());

View file

@ -19,9 +19,37 @@ namespace CSVWorld
class ScriptEdit : public QTextEdit
{
Q_OBJECT
public:
class ChangeLock
{
ScriptEdit& mEdit;
ChangeLock (const ChangeLock&);
ChangeLock& operator= (const ChangeLock&);
public:
ChangeLock (ScriptEdit& edit);
~ChangeLock();
};
friend class ChangeLock;
private:
int mChangeLocked;
public:
ScriptEdit (QWidget* parent, const CSMDoc::Document& document);
/// Should changes to the data be ignored (i.e. not cause updated)?
///
/// \note This mechanism is used to avoid infinite update recursions
bool isChangeLocked() const;
private:
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
const CSMDoc::Document& mDocument;

View file

@ -15,18 +15,8 @@
#include "scripthighlighter.hpp"
#include "scriptedit.hpp"
CSVWorld::ScriptSubView::ChangeLock::ChangeLock (ScriptSubView& view) : mView (view)
{
++mView.mChangeLocked;
}
CSVWorld::ScriptSubView::ChangeLock::~ChangeLock()
{
--mView.mChangeLocked;
}
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: SubView (id), mDocument (document), mColumn (-1), mChangeLocked (0)
: SubView (id), mDocument (document), mColumn (-1)
{
setWidget (mEditor = new ScriptEdit (this, mDocument));
@ -78,10 +68,10 @@ void CSVWorld::ScriptSubView::idListChanged()
void CSVWorld::ScriptSubView::textChanged()
{
if (mChangeLocked)
if (mEditor->isChangeLocked())
return;
ChangeLock lock (*this);
ScriptEdit::ChangeLock lock (*mEditor);
mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel,
mModel->getModelIndex (getUniversalId().getId(), mColumn), mEditor->toPlainText()));
@ -89,10 +79,10 @@ void CSVWorld::ScriptSubView::textChanged()
void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
if (mChangeLocked)
if (mEditor->isChangeLocked())
return;
ChangeLock lock (*this);
ScriptEdit::ChangeLock lock (*mEditor);
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
@ -115,10 +105,10 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i
void CSVWorld::ScriptSubView::updateHighlighting()
{
if (mChangeLocked)
if (mEditor->isChangeLocked())
return;
ChangeLock lock (*this);
ScriptEdit::ChangeLock lock (*mEditor);
mHighlighter->rehighlight();
}

View file

@ -21,34 +21,19 @@ namespace CSMWorld
namespace CSVWorld
{
class ScriptHighlighter;
class ScriptEdit;
class ScriptSubView : public CSVDoc::SubView
{
Q_OBJECT
QTextEdit *mEditor;
ScriptEdit *mEditor;
CSMDoc::Document& mDocument;
CSMWorld::IdTable *mModel;
int mColumn;
int mChangeLocked;
ScriptHighlighter *mHighlighter;
QTimer mUpdateTimer;
class ChangeLock
{
ScriptSubView& mView;
ChangeLock (const ChangeLock&);
ChangeLock& operator= (const ChangeLock&);
public:
ChangeLock (ScriptSubView& view);
~ChangeLock();
};
friend class ChangeLock;
public:
ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);