moved syntax highlighter from ScriptSubView to ScriptEdit

deque
Marc Zinnschlag 11 years ago
parent d4981c3037
commit c2e3709d0f

@ -6,9 +6,13 @@
#include <QRegExp>
#include <QString>
#include "../../model/doc/document.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/tablemimedata.hpp"
#include "scripthighlighter.hpp"
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
{
++mEdit.mChangeLocked;
@ -60,6 +64,14 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& docum
<<CSMWorld::UniversalId::Type_Weapon
<<CSMWorld::UniversalId::Type_Script
<<CSMWorld::UniversalId::Type_Region;
mHighlighter = new ScriptHighlighter (document.getData(), ScriptEdit::document());
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
connect (&mUpdateTimer, SIGNAL (timeout()), this, SLOT (updateHighlighting()));
mUpdateTimer.setSingleShot (true);
}
bool CSVWorld::ScriptEdit::isChangeLocked() const
@ -127,3 +139,21 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) const
//I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
return !(string.contains(mWhiteListQoutes));
}
void CSVWorld::ScriptEdit::idListChanged()
{
mHighlighter->invalidateIds();
if (!mUpdateTimer.isActive())
mUpdateTimer.start (0);
}
void CSVWorld::ScriptEdit::updateHighlighting()
{
if (isChangeLocked())
return;
ChangeLock lock (*this);
mHighlighter->rehighlight();
}

@ -1,8 +1,9 @@
#ifndef SCRIPTEDIT_H
#define SCRIPTEDIT_H
#include <qtextedit.h>
#include <QTextEdit>
#include <QVector>
#include <QTimer>
#include "../../model/world/universalid.hpp"
@ -16,6 +17,8 @@ namespace CSMDoc
namespace CSVWorld
{
class ScriptHighlighter;
class ScriptEdit : public QTextEdit
{
Q_OBJECT
@ -40,6 +43,8 @@ namespace CSVWorld
private:
int mChangeLocked;
ScriptHighlighter *mHighlighter;
QTimer mUpdateTimer;
public:
@ -62,6 +67,12 @@ namespace CSVWorld
void dragMoveEvent (QDragMoveEvent* event);
bool stringNeedsQuote(const std::string& id) const;
private slots:
void idListChanged();
void updateHighlighting();
};
}
#endif // SCRIPTEDIT_H

@ -3,8 +3,6 @@
#include <stdexcept>
#include <QTextEdit>
#include "../../model/doc/document.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/data.hpp"
@ -12,7 +10,6 @@
#include "../../model/world/commands.hpp"
#include "../../model/world/idtable.hpp"
#include "scripthighlighter.hpp"
#include "scriptedit.hpp"
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
@ -43,14 +40,6 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
mHighlighter = new ScriptHighlighter (document.getData(), mEditor->document());
connect (&mUpdateTimer, SIGNAL (timeout()), this, SLOT (updateHighlighting()));
mUpdateTimer.setSingleShot (true);
}
void CSVWorld::ScriptSubView::setEditLock (bool locked)
@ -58,14 +47,6 @@ void CSVWorld::ScriptSubView::setEditLock (bool locked)
mEditor->setReadOnly (locked);
}
void CSVWorld::ScriptSubView::idListChanged()
{
mHighlighter->invalidateIds();
if (!mUpdateTimer.isActive())
mUpdateTimer.start (0);
}
void CSVWorld::ScriptSubView::textChanged()
{
if (mEditor->isChangeLocked())
@ -103,12 +84,3 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i
deleteLater();
}
void CSVWorld::ScriptSubView::updateHighlighting()
{
if (mEditor->isChangeLocked())
return;
ScriptEdit::ChangeLock lock (*mEditor);
mHighlighter->rehighlight();
}

@ -3,9 +3,6 @@
#include "../doc/subview.hpp"
#include <QTimer>
class QTextEdit;
class QModelIndex;
namespace CSMDoc
@ -20,7 +17,6 @@ namespace CSMWorld
namespace CSVWorld
{
class ScriptHighlighter;
class ScriptEdit;
class ScriptSubView : public CSVDoc::SubView
@ -31,8 +27,6 @@ namespace CSVWorld
CSMDoc::Document& mDocument;
CSMWorld::IdTable *mModel;
int mColumn;
ScriptHighlighter *mHighlighter;
QTimer mUpdateTimer;
public:
@ -42,17 +36,11 @@ namespace CSVWorld
public slots:
void idListChanged();
void textChanged();
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
private slots:
void updateHighlighting();
};
}

Loading…
Cancel
Save