Carousel
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Pages
Public Slots | Public Member Functions | Protected Member Functions | List of all members
ScriptUnit Class Reference

It is a default implementation of the IScriptUnit interface. More...

#include <ScriptUnit.h>

Inherits IScriptUnit.

Public Slots

void clear ()
 
bool load ()
 
bool load (const QString &filePath)
 
bool run ()
 
bool save ()
 
bool saveAs (const QString &filePath)
 
- Public Slots inherited from IScriptUnit
virtual void clear ()=0
 
virtual bool load ()=0
 
virtual bool load (const QString &filePath)=0
 
virtual bool run ()=0
 
virtual bool save ()=0
 
virtual bool saveAs (const QString &filePath)=0
 

Public Member Functions

 ScriptUnit (IScriptEngineFactory *factory, QObject *parent=nullptr)
 
 ScriptUnit (const QString &filePath, IScriptEngineFactory *factory, QObject *parent=nullptr)
 
QString absoluteFilePath () const
 
QString fileName () const
 
bool isLoaded () const
 
QTextDocumentscript ()
 
const QTextDocumentscript () const
 
QString scriptText () const
 
void setScriptText (const QString &plainText)
 
- Public Member Functions inherited from IScriptUnit
 IScriptUnit ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 
- Public Member Functions inherited from IOutputHandler
 IOutputHandler ()
 
virtual void print (const QString &message)=0
 

Protected Member Functions

virtual bool saveToFile (const QString &filePath)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Signals inherited from IScriptUnit
void error (const QString &error)
 
void fileNameChanged ()
 
void printed (const QString &message)
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from IScriptUnit
QString absoluteFilePath
 
QString fileName
 
bool isLoaded
 
QTextDocument script
 
QString scriptText
 
- Properties inherited from QObject
 objectName
 

Detailed Description

It is a default implementation of the IScriptUnit interface.

The IScriptCollection interface is a storage for that units so you usually should to get IScriptCollection reference to create or to get some script unit.

This class itself does not provide any GUI capabilities, indeed it is rendered using ScriptUnitView widget. Since script is stored as text inside the QTextDocument, it is possible to setup this document to widgets like QTextEdit. It allows to use all benefits like code highliting and undo/redo.

See Also
IScriptCollection, ScriptUnitView

Constructor & Destructor Documentation

ScriptUnit::ScriptUnit ( IScriptEngineFactory factory,
QObject parent = nullptr 
)
explicit

Initializes a new instance of the ScriptUnit class with empty script body and specified factory for QScriptEngine creation for the each run() call.

Call load(file) to load some script.

ScriptUnit::ScriptUnit ( const QString filePath,
IScriptEngineFactory factory,
QObject parent = nullptr 
)

Initializes a new instance of the ScriptUnit class with empty script body and specified factory for QScriptEngine creation for the each run() call.

Call load() to load script from the filePath.

Member Function Documentation

bool ScriptUnit::isLoaded ( ) const
virtual

Returns true if script was loaded from the file.

Implements IScriptUnit.

QString ScriptUnit::absoluteFilePath ( ) const
virtual

Gets the absolute path to the file from wich script was loaded (if it was loaded).

Implements IScriptUnit.

QString ScriptUnit::fileName ( ) const
virtual

Gets the file name from wich script was loaded (if it was loaded).

See Also
QFileInfo::fileName, absoluteFilePath

Implements IScriptUnit.

QString ScriptUnit::scriptText ( ) const
virtual

Gets script as a plain text.

Implements IScriptUnit.

void ScriptUnit::setScriptText ( const QString plainText)
virtual

Sets a new plainText as a script.

Implements IScriptUnit.

QTextDocument* ScriptUnit::script ( )
virtual

Gets script as a document.

Implements IScriptUnit.

const QTextDocument* ScriptUnit::script ( ) const
virtual

Gets script as a document.

Implements IScriptUnit.

bool ScriptUnit::load ( )
slot

Tries to load script from the fileName(). Returns true, if loading was successful.

bool ScriptUnit::load ( const QString filePath)
slot

Tries to load script from a filePath. Sets filePath as a current file name and returns true, if loading was successful.

Since after successful loading file name is changed, the fileNameChanged() signal is emitted.

void ScriptUnit::clear ( )
slot

Clears script body.

bool ScriptUnit::save ( )
slot

Tries to save script to the fileName(). Returns true, if saving was successful.

bool ScriptUnit::saveAs ( const QString filePath)
slot

Tries to save script to a filePath. Sets filePath as a current file name and returns true, if saving was successful.

Since after successful saving file name is changed, the fileNameChanged() signal is emitted.

bool ScriptUnit::run ( )
slot

Tries to save script to the fileName(). All print() functions called from the script will be emitted as printed() signal. Returns true, if script was evaluated without errors. Otherwise, returns false and emits the error() signal.