Menu

[c54480]: / scripting.cpp  Maximize  Restore  History

Download this file

126 lines (103 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "scripting.h"
#include "branchitem.h"
#include "imageitem.h"
#include "mainwindow.h"
#include "misc.h"
#include "vymmodelwrapper.h"
#include "vymtext.h"
#include "xlink.h"
extern Main *mainWindow;
extern QString vymVersion;
///////////////////////////////////////////////////////////////////////////
void logError(QScriptContext *context, QScriptContext::Error error, const QString &text)
{
if (context)
context->throwError( error, text);
else
qDebug()<<"VymWrapper: "<<text;
}
///////////////////////////////////////////////////////////////////////////
VymScriptContext::VymScriptContext()
{
}
QString VymScriptContext::setResult( const QString &r)
{
context()->engine()->globalObject().setProperty("lastResult", r );
return r;
}
bool VymScriptContext::setResult( bool r)
{
context()->engine()->globalObject().setProperty("lastResult", r );
return r;
}
int VymScriptContext::setResult( int r)
{
context()->engine()->globalObject().setProperty("lastResult", r );
return r;
}
///////////////////////////////////////////////////////////////////////////
VymWrapper::VymWrapper()
{
}
void VymWrapper::clearConsole()
{
mainWindow->clearScriptOutput();
}
QObject* VymWrapper::currentMap()
{
return mainWindow->getCurrentModelWrapper();
}
bool VymWrapper::loadMap( const QString &filename )
{
bool r;
if ( File::Success == mainWindow->fileLoad( filename, NewMap, VymMap ) )
r = true;
else
r = false;
return setResult( r );
}
int VymWrapper::mapCount()
{
context()->engine()->globalObject().setProperty("lastResult", mainWindow->modelCount() );
return setResult( mainWindow->modelCount() );
}
void VymWrapper::selectMap(uint n)
{
if ( !mainWindow->gotoWindow( n ))
{
logError( context(), QScriptContext::RangeError, QString("Map '%1' not available.").arg(n) );
}
}
void VymWrapper::toggleTreeEditor()
{
mainWindow->windowToggleTreeEditor();
}
QString VymWrapper::loadFile( const QString &filename) // FIXME-3 error handling missing (in vymmodel and here)
{
QString s;
loadStringFromDisk(filename, s);
return s;
}
void VymWrapper::saveFile( const QString &filename, const QString &s) // FIXME-3 error handling missing (in vymmodel and here)
{
saveStringToDisk(filename, s);
}
QString VymWrapper::version()
{
return setResult( vymVersion );
}
// See also http://doc.qt.io/qt-5/qscriptengine.html#newFunction
Selection::Selection()
{
modelWrapper = NULL;
}
void Selection::test()
{
qDebug() << "Selection::testSelection called"; // TODO debug
if (modelWrapper) modelWrapper->setHeadingPlainText("huhu!");
}
void Selection::setModel(VymModelWrapper *mw)
{
qDebug() << "Selection::setModel called: " << mw; // TODO debug
modelWrapper = mw;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.